Binary Search Tree Simulator
For every node, all values in the left subtree are smaller and all values in the right subtree are larger. This ordering rule determines search, insertion, deletion, predecessor, successor, minimum, maximum, and sorted traversal behavior.
Balanced operationsO(log n)
Worst-case operationsO(n)
Inorder traversalSorted values
Duplicate policyRejected
BST operations
Example tree loaded. Choose an operation.
Nodes0
Height0
Leaves0
Comparisons0
Search / operation path
—
Traversal result
—
Deletion cases
leaf: remove it one child: replace it with that child two children: copy the inorder successor delete that successor from the right subtree
BST concepts
Search decisions
At each node, equality finishes the search. A smaller target moves left; a larger target moves right.
Predecessor and successor
The predecessor is the greatest smaller key. The successor is the smallest larger key. They may be found in a subtree or among ancestors.
Deletion
Deleting a node with two children uses the minimum node in its right subtree, called the inorder successor.
Degeneration
Inserting sorted values can create a chain. The BST stays valid, but height and operation time become linear.
Traversal orders
| Traversal | Order | Typical use |
|---|---|---|
| Inorder | Left, Root, Right | Read BST values in sorted order. |
| Preorder | Root, Left, Right | Serialize or copy tree structure. |
| Postorder | Left, Right, Root | Delete or evaluate subtrees first. |
| Level order | Breadth by breadth | Inspect the tree one level at a time. |