The Insert into a Binary Search Tree interview question asks you to add a new value to an existing BST while maintaining the BST property (left child < parent < right child). You are guaranteed that the new value does not already exist in the tree. There are often multiple valid ways to insert, but the simplest is to add it as a new leaf.
Companies like Microsoft and Google use the Insert into a BST coding problem to evaluate basic recursive thinking and understanding of tree invariants. It’s a core Binary Tree interview pattern that checks if you can navigate a hierarchy based on value comparisons.
This problem uses Recursive Search and Placement.
val < root.val, move to the left subtree.val > root.val.BST: 4 is root, 2 is left, 7 is right. Insert 5.
7, : Go left.7 is null. Insert 5 here.
Result: 4 -> {2, 7}, 7 -> {5, null}.root.left or root.right.Practice both recursive and iterative versions of this. The iterative version uses a while loop and a trailing parent pointer, which is a great way to demonstrate memory management skills without using the recursion stack.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Delete Node in a BST | Medium | Solve | |
| Inorder Successor in BST II | Medium | Solve | |
| Search in a Binary Search Tree | Easy | Solve | |
| Convert BST to Greater Tree | Medium | Solve | |
| Recover Binary Search Tree | Medium | Solve |