We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This does not adhere to the constructor for the BST. For example, as soon as 1 is entered into the tree, the constructor would go down the left path until it got to node(2).left and place it there. It would never go down the right path since 1 is lower than the root.
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
I think in this counter example it wouldnt work:
v1 is 1 and v2 is 7
Answer we would get is 4 and the correct answer is 6.
I saw no such BST because BST strictly follows elements(root.left)
This does not adhere to the constructor for the BST. For example, as soon as 1 is entered into the tree, the constructor would go down the left path until it got to node(2).left and place it there. It would never go down the right path since 1 is lower than the root.
1 cannot go to the right of 4 as it will break the BST invariant