While you are constructing a tree, you should store every node's
parent in its field. Then the corresponding tree as you referred above
should be
           1(0)
         /       \
     2(1)       3(1)
    /  \           /   \
 4(2)  5(2)   6(3)   7(3)
 /   \       /  \     / \      /  \
8(4) 9(4) 10(5) 11(5) 12(6) 13(6) 14(7) 15(7)

On Mon, Sep 6, 2010 at 11:08 PM, Debajyoti Sarma
<sarma.debajy...@gmail.com> wrote:
> How to print the path from root to a specific node in a binary tree??
> I want to store the path in a array[] of node*.
> can it b done in O(n) or less?
> Remember it's not BST.
>
>              1
>          /       \
>      2              3
>     /  \           /   \
>  4     5       6        7
>  / \    /  \     / \      /  \
> 8 9 10 11 12 13 14 15
>
> path of 6 will b 1,3,6.
> path of 9 will be 1,2,5,11
>
> --
> 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.
>
>

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