mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Least Common Ancestor: Vivek Sir

3 posters

Go down

Least Common Ancestor: Vivek Sir Empty Least Common Ancestor: Vivek Sir

Post  shivang Mon Feb 02, 2009 3:32 am

How to find the Least Common Ancestor of the 2 given nos in a binary search tree?
shivang
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

Least Common Ancestor: Vivek Sir Empty Re: Least Common Ancestor: Vivek Sir

Post  tirth Mon Feb 02, 2009 3:32 pm

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

tirth

Posts : 3
Join date : 2009-01-30

Back to top Go down

Least Common Ancestor: Vivek Sir Empty Re: Least Common Ancestor: Vivek Sir

Post  ramthegreatcv Tue Feb 03, 2009 12:53 am

boundary conditions??

it fails if one is ancestor of another.
just a small change is required.
ramthegreatcv
ramthegreatcv

Posts : 55
Join date : 2009-01-30
Age : 35

Back to top Go down

Least Common Ancestor: Vivek Sir Empty Re: Least Common Ancestor: Vivek Sir

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum