Following is the Solution for sum of subsets with complexity O(n).
suppose we have to find out the 2 numbers from array(Set) whose sum is
equivalent to certain no: k

int main(){
int a[10]={1,2,3,4,5,6,7,8,9,10};
int sum =15;   //no. to find for
int i=0,j;
front=i;
back=10
while(front<back){
 if(sum>a[front]+a[back])  front++;
 else if(sum<a[front]+a[back])  back--;
else if(sum=a[front]+a[back]){
          printf("%d\t",a[front]); front++;
          printf("%d\n",a[back]);   back-- ;
} else {
           break;
}
}
return 0;
}

In same way we can make for 3 , 4 numbers from array eq. to certain k.

If you have any doubt please ask .

Regards ,
Peeyush Bishnoi

On 4/2/07, pramod <[EMAIL PROTECTED]> wrote:
>
>
> Dor,
>
> If I understand the problem correctly, we don't know what are all the
> elements in S (that's what we need to find).
> So how are you going to pick 'k' first and how do you know of 'x'
> belonging to S?
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to