As far as I understand, your solution will always contain the path that
essentially start from root. But the actual problem states that the path
may not necessarily start from root.

On Fri, Nov 11, 2011 at 1:21 PM, UTKARSH SRIVASTAV
<usrivastav...@gmail.com>wrote:

>
> correct me if I am wrong
>
> #include<stdio.h>
>
> struct node
> {
>     int data;
>     struct node *left;
>     struct node * right;
> }*root;
>
> int sum(int s,struct node *p,int ar[],int l)
> {
>     if(p == NULL )
>     {
>         return 0;
>     }
>     if(p->left == NULL && p->right == NULL)
>     {
>         if( s - p->data == 0)
>         {
>             ar[l++] = p->data;
>             int i;
>             for( i = 0 ;i < l ;i++)
>             {
>                 printf("%d ",ar[i]);
>             }
>             printf("\n");
>         }
>
>     }
>     ar[l++] = p->data;
>     sum(s - p->data, p->left , ar , l);
>     sum(s - p->data, p->right , ar, l);
>     return 0;
> }
>
> struct node * getnode(int k)
> {
>     struct node *temp = malloc(sizeof(struct node));
>     temp->data = k;
>     temp->left= NULL;
>     temp->right = NULL;
>     return temp;
> }
>
> main()
> {
>     int ar[50],value;
>     root = getnode(5);
>     root->left= getnode(2);
>     root->right = getnode(2);
>     root->left->left = getnode(7);
>     root->left->right = getnode(8);
>     root->right->left = getnode(3);
>     root->right->right = getnode(7);
>     value = 14;
>     sum(value,root,ar,0);
>     return 0;
>
> }
>
> On Fri, Nov 11, 2011 at 12:38 PM, aniket chatterjee 
> <aniket...@gmail.com>wrote:
>
>> Write a recursive function that will store each root to leaf path in an
>> array. Now for each root to leaf path find the subarray which sums up to X.
>>
>> On Thu, Nov 10, 2011 at 11:53 PM, AMAN AGARWAL <mnnit.a...@gmail.com>wrote:
>>
>>> Hi All,
>>>
>>> Please give me the solution of this problem.
>>>
>>> A binary tree and a number X is given. Find all the paths(not
>>> necessarily starting from root) such that the sum equals X.
>>>
>>>
>>> Regards,
>>> Aman.
>>>
>>> --
>>> AMAN AGARWAL
>>> "Success is not final, Failure is not fatal: It is the courage to
>>> continue that counts!"
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> *UTKARSH SRIVASTAV
> CSE-3
> B-Tech 3rd Year
> @MNNIT ALLAHABAD*
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to