Binary Search Tree : Lowest Common Ancestor

  • + 5 comments

    I think in this counter example it wouldnt work:

    v1 is 1 and v2 is 7

        4       
      /   \
    2       6
     \     /  \
      3   5    7    
         /
        1
    

    Answer we would get is 4 and the correct answer is 6.

    • + 0 comments

      I saw no such BST because BST strictly follows elements(root.left)

    • + 0 comments

      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.

    • + 0 comments

      1 cannot go to the right of 4 as it will break the BST invariant