Inorder Successor in Binary Search Tree
Question
Give a node, find the inorder successor on a BST. Input Node: target, root.
Solution
If target.right!=null, return the smallest node in the right subtree.
If target.right==null, search the path from root to target, the result is located within the path. We need to find the last node from which we traverse into the left subtree during the search.
Follow up
What if each node do tell its parent node? In this case, the root node is not given.
Last updated