Strategy: subtract the node value from the sum when recurring down,
 and check to see if the remaining sum is 0 when you run out of tree.
let sum be subsum

int * PathSum(struct node* node, int sum) {
  int i=0;
  if (subsum == 0) {
    return(array);
  }
  elseif(node==NULL){
       return;
   }
  else {
      array[i++]=node->data;
  // otherwise check both subtrees
    int subSum = sum - node->data;
    return(hasPathSum(node->left, subSum) ||
           hasPathSum(node->right, subSum));
  }
}


On Fri, May 14, 2010 at 12:39 PM, divya <sweetdivya....@gmail.com> wrote:

> write a c code to print the path in a tree sum of whose nodes equals a
> given number..
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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