The idea is to traverse the binary tree in post order and find out all
the path sums and store them. Use a hashtable or any other data
structure to store the possible paths rooted at a node and going
down-only. Now we can construct all paths going through a node from
itself and its childrens' paths.

If the idea is not clear, I will post the detailed algo..




On Wed, Jun 29, 2011 at 9:16 AM, Akshata Sharma
<akshatasharm...@gmail.com> wrote:
> ya..there can be other paths, like the on you mentioned..
>
> On Wed, Jun 29, 2011 at 9:25 PM, Piyush Sinha <ecstasy.piy...@gmail.com>
> wrote:
>>
>> 7+3 also give the sum to be 10???
>>
>> On 6/29/11, Akshata Sharma <akshatasharm...@gmail.com> wrote:
>> > How to find a path in a given binary tree which sums up to a given
>> > target
>> > value?
>> > for example if the given BT is
>> >
>> >    5
>> >   / \
>> >  3   2
>> >  /
>> > 7
>> > and if the target is 10, then the path is ---- root(5) + left node(3) +
>> > right node (2).
>> >
>> > --
>> > 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.
>> >
>> >
>>
>>
>> --
>> *Piyush Sinha*
>> *IIIT, Allahabad*
>> *+91-8792136657*
>> *+91-7483122727*
>> *https://www.facebook.com/profile.php?id=100000655377926 *
>>
>> --
>> 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.
>

-- 
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