Sorry for not understanding the problem at first...
I hope this solution will find the all the subsets from set S . The sum of
elements in subset is equivalent to certain k.

fun(int a[],int k){
                int i,j;
                int k1;
                for(i=0;i<10;i++){
                        k1=a[i];
                        j=i+1;


while(j<10){                                             //if we have 10
elements in set S;
                                k1=k1+a[j];
                                if(k>k1){
                                        j++;
                                }else if(k==k1){
                                        printf("True\t");
                                        while(k1!=0){
                                                printf("%d\t",a[j]);
                                                k1=k1-a[j];
                                                j--;
                                        }
                                        printf("\n");
                                }else if(k<k1)  {
                                        break;
                                }
                        }
                }
        }

---
Regards
Peeyush Bishnoi



On 4/2/07, Peeyush Bishnoi <[EMAIL PROTECTED]> wrote:
>
> 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