Conceptual
Login

Finding the Inorder Successor of a Node in a Binary Search Tree

The inorder successor of a node in a binary search tree is the node that immediately follows it in the inorder traversal sequence, which for a BST is the next-largest key, since inorder traversal of a BST visits keys in sorted order. The successor is determined by two mutually exclusive structural cases: if the node has a right subtree, the successor is the leftmost (minimum) node of that subtree; if it does not, the successor is the nearest ancestor for which the node lies in the left subtree, and no successor exists when the node holds the maximum key. Locating the successor by these structural rules costs O(H) in the height of the tree rather than the O(N) of a full traversal, aligning successor lookup with the other O(H) BST operations (search, insertion, deletion); this belongs to the data structures and algorithms subfield of computer science, specifically ordered-dictionary operations on binary search trees.