[algogeeks] Find the path in two nodes of a binary search tree

2012-01-02 Thread top coder
Suppose you have a tree. A binary tree (for something like
simplicity :p). You are traversing it (using infix, postfix or prefix)
to search for a node. You find your required node. You just realized
that you need to know the path from this node back to the root node
(and/or vice versa). Given the following description of the structure
of the tree node that you “cant” change:

struct node{Data data; node *right,*left;};

what will you strategy be to tackle this problem.

To make it more intresting (or maybe just the application of the above
problem) suppose you find the node A and a node B in consecutive
searches. Now what will your strategy be to show a path from A to B.
(not neccesarily from the root of the whole tree, but possibly).

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



Re: [algogeeks] Find the path in two nodes of a binary search tree

2012-01-02 Thread Abhishek Gupta
we might implement it using recursive calls where once found..the node is
printed and true is returned and if leaf is reached...false is
returnedall the function calls getting true will again print and return
true...and false will just return false without printing...this way we can
print only nodes which are in path from root to target node...i can assume
it to be a simple binary seach tree...




On Mon, Jan 2, 2012 at 10:12 PM, top coder topcode...@gmail.com wrote:

 Suppose you have a tree. A binary tree (for something like
 simplicity :p). You are traversing it (using infix, postfix or prefix)
 to search for a node. You find your required node. You just realized
 that you need to know the path from this node back to the root node
 (and/or vice versa). Given the following description of the structure
 of the tree node that you “cant” change:

 struct node{Data data; node *right,*left;};

 what will you strategy be to tackle this problem.

 To make it more intresting (or maybe just the application of the above
 problem) suppose you find the node A and a node B in consecutive
 searches. Now what will your strategy be to show a path from A to B.
 (not neccesarily from the root of the whole tree, but possibly).

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




-- 
Thanks  Regards
Abhishek Gupta
BITS, Pilani

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



[algogeeks] Find the path in two nodes of a binary search tree

2011-01-21 Thread snehal jain
Suppose you have a tree. A binary tree (for something like
simplicity :p). You are traversing it (using infix, postfix or prefix)
to search for a node. You find your required node. You just realized
that you need to know the path from this node back to the root node
(and/or vice versa). Given the following description of the structure
of the tree node that you “cant” change:

struct node{Data data; node *right,*left;};

what will you strategy be to tackle this problem.

To make it more intresting (or maybe just the application of the above
problem) suppose you find the node A and a node B in consecutive
searches. Now what will your strategy be to show a path from A to B.
(not neccesarily from the root of the whole tree, but possibly).

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