Least Common Ancestor: Vivek Sir
3 posters
Page 1 of 1
Least Common Ancestor: Vivek Sir
How to find the Least Common Ancestor of the 2 given nos in a binary search tree?
shivang- Posts : 42
Join date : 2009-01-30
Age : 35
Re: Least Common Ancestor: Vivek Sir
traverse karna shuru karoo root se...and keep on coming down the tree..as we do for a binary search tree traversal
agar dono child node(which will be root for the first time) se larger ya small hai..then keep coming down the tree recursively ..until .we reach a node at where first child is bigger than the node and the other child is smaller than the node or the viceversa...this particular node in the tree is the required least common ancestor
agar dono child node(which will be root for the first time) se larger ya small hai..then keep coming down the tree recursively ..until .we reach a node at where first child is bigger than the node and the other child is smaller than the node or the viceversa...this particular node in the tree is the required least common ancestor
tirth- Posts : 3
Join date : 2009-01-30
Re: Least Common Ancestor: Vivek Sir
boundary conditions??
it fails if one is ancestor of another.
just a small change is required.
it fails if one is ancestor of another.
just a small change is required.
ramthegreatcv- Posts : 55
Join date : 2009-01-30
Age : 35
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum