advanced9 min read·Updated September 29, 2026

Delete a Node in a BST Explained: Tracing Deleting 3 then 5

Master BST deletion through a clear worked example deleting 3 and root 5. Learn structural cases, successor logic, mental models, and complexity.

By Learnisim AI·Published September 29, 2026
LEARNING ARCSetup → Model in the example → Full trace → Twist → Edge cases → Apply
PREREQUISITES
  • Binary Search Tree properties
  • BST search and insertion
  • Tree traversals
BST Deletion: Delete 3, Then Delete 5 (BST: 5, 3, 6, 2, 4, null, 7) Two-child deletion uses in-order successor to preserve BST invariant: left < parent < right 1. Initial BST 5 3 6 2 4 7 Target 1: Delete node 3 (Has 2 children: 2 and 4) Find successor in right subtree Successor = 4 (min of right) Action: Copy 4 to node 3, then delete leaf 4 2. After Deleting 3 5 4 6 2 7 Target 2: Delete root 5 (Root also has 2 children: 4 and 6) Find successor in right subtree Successor of 5 is 6 (min of right) Action: Copy 6 to root, then delete old node 6 3. Final BST (Root 6) 6 4 7 2 Resulting Valid BST Root is now 6 Left subtree: {4, 2} Right subtree: {7} All BST invariants intact! No orphaned nodes or violations
In BST 5,3,6,2,4,null,7 delete 3, then delete 5 overview diagram
Why

Why BST Deletion Breaks Simple Traversal Rules

Phase 1: The Broken Tree Problem

Imagine you are handed the binary search tree represented by the sequence 5, 3, 6, 2, 4, null, 7. Here, 5 is the root, with a left subtree rooted at 3 (having children 2 and 4) and a right subtree rooted at 6 (having a right child 7). Everything is orderly: left descendants are smaller, right descendants are larger. But what happens when you decide to delete node 3, and then root node 5?
If you simply sever a node from its parent like a leaf on a linked list, you risk stranding entire subtrees or violating the fundamental BST invariant where every left child is less than its parent and every right child is greater. Deleting a leaf like 2 or 7 is trivial, but deleting an internal node with one or two children creates structural gaps. You cannot just remove node 3 and leave its children 2 and 4 floating in the memory void, nor can you arbitrarily promote 4 to take 3's place without checking whether the rest of the tree still respects the ordering rules.
This is why BST deletion demands a systematic strategy: you are not just updating a single pointer, you are surgically repairing a hierarchical network. Throughout this guide, we will track the exact sequence of deletions on our initial BST: first deleting 3 (a node with two children), and then deleting root 5 (also with two children), observing every intermediate pointer mutation along the way.
python
# Given BST: 5, 3, 6, 2, 4, null, 7
# Goal: Delete 3, then delete 5.
# Question: Explain in 1-2 sentences why deleting node 3 is structurally harder than deleting leaf node 7.
Why BST Deletion Breaks Simple Traversal Rules (Delete 3, then Delete 5) 1. Initial BST: [5,3,6,2,4,null,7] 5 3 6 2 4 7 Why Deleting 3 is Hard: Node 3 has TWO children (2 and 4). Simply removing it strands subtrees or violates BST ordering rules. Strategy: Find In-Order Successor (4) 2. After Deleting 3 (Promote 4) 5 4 6 2 7 Next Challenge: Delete Root 5 Root 5 also has TWO children (4 and 6). Must find successor in right subtree or predecessor in left subtree. Successor is min of right sub-tree (6) 3. After Deleting 5 6 4 7 2 Final Valid BST Successor 6 takes root. Left subtree (4,2) and right child (7) attach without invariant break!
Why BST Deletion Breaks Simple Traversal Rules diagram
Model

The Three Structural Cases of Binary Search Tree Deletion

Phase 2: The Model

When we perform structural surgery on a Binary Search Tree, we cannot simply snip a pointer without violating the core invariant: for any node, all left descendants are smaller, and all right descendants are larger. In our working example tree 5 with left subtree 3 (having children 2 and 4) and right subtree 6 (having right child 7), deleting a node falls into one of three distinct topological cases.
First, consider deleting a leaf node (such as 2 or 7). Because it has no descendants, we only need to sever its parent's pointer by replacing it with null, keeping the rest of the tree intact.
Second, consider deleting a node with exactly one child. The sole subtree can safely slide up to take the deleted node's place in the parent's pointer field, bypassing the removed node entirely.
Third, consider deleting a node with two children, which is what happens when we delete 3 or root 5 in our working example. Because both left and right subtrees are populated, we cannot replace 3 with a single child without leaving an orphaned branch. Instead, we find the in-order successor (the minimum value in the right subtree) or the in-order predecessor, copy its value into the target node, and then recursively delete that successor from its original position.
5
/ \
3 6
/ \ \
2 4 7
When we delete 3, it has two children (2 and 4). Its right subtree starts at 4, which has no left child, making 4 the in-order successor. Copying 4 into node 3's position and removing the old 4 leaf preserves the BST property without breaking the remaining hierarchy.
Try this: Given the working tree: root 5, left 3 (children 2, 4), right 6 (child 7). Explain which of the three structural cases applies when deleting node 2 versus deleting node 3.
Binary Search Tree Deletion — The Three Structural Cases Preserving the BST invariant: Left < Node < Right across topological surgery Initial Working Tree 5 3 6 2 4 7 Key Invariant & Order • In-order successor of 3 is 4 • Left subtree < Node < Right subtree • Deleting root 5 triggers 2 children case (successor is 6) Follow topological cases on right → Case 1: Leaf Node has 0 children (e.g. Node 2 or 7) Action: Simply sever parent's pointer & replace with null. Result: Zero tree reorganization required elsewhere. Case 2: 1 Child Node has exactly 1 child subtree Action: Sole child slides up to take deleted node's place. Result: Parent pointer bypasses removed node completely. Case 3: 2 Children Node has both left & right subtrees (e.g. Delete 3) 1. Find in-order successor (min value in right subtree → node 4) 2. Copy successor's value into target node (node 3 becomes 4) 3. Recursively delete the old successor leaf from its original spot. Result: BST invariant fully preserved without orphaned branches!
The Three Structural Cases of Binary Search Tree Deletion diagram
Worked example

Tracing Two Successive Deletions in Our BST

Phase 3: The Complete Walkthrough

Let us trace the exact sequence for our working example: a BST constructed from .
5
/ \
3 6
/ \ \
2 4 7

Step 1: Delete Node 3 (Two Children)

Given: We want to delete key 3. Node 3 has two children (2 and 4).
Steps:
1. Locate node 3 starting from root 5 (go left). Confirm it has both a left child (2) and a right child (4).
2. Find the in-order successor in the right subtree of 3. The right subtree root is 4, and it has no left child. Thus, the successor value is 4.
3. Copy the successor value (4) into node 3. Node 3 now holds 4, temporarily creating a duplicate 4 in its right child.
4. Recursively delete the successor node (4) from the right subtree. Since 4 is a leaf, it is removed by updating its parent's right pointer to null.
Result after deleting 3:
5
/ \
4 6
/ \
2 7

Step 2: Delete Root 5 (Two Children)

Given: From the original BST structure (or the updated one, but let us stick to the primary prompt sequence: deleting 3 then deleting root 5 from that modified state or original state), let us trace deleting root 5.
Steps:
1. Locate root 5. It has two children (4 on the left, 6 on the right after our deletion of 3).
2. Find the in-order successor in the right subtree (rooted at 6). The minimum value in the right subtree is 6 (since 6 has no left child, only right child 7).
3. Copy successor value 6 into the root position. The root now holds 6.
4. Recursively delete the successor node (6) from its original position. Since 6 has a right child (7), deleting 6 falls under the single-child case: replace 6 with its right child 7.
Result after deleting 5:
6
/ \
4 7
/
2
This yields our final structural state: 6, 4, 7, 2. Notice how every deletion preserves the BST invariant ().
Phase 3: Tracing Two Successive Deletions (Node 3, then Root 5) 1. Initial BST 5 3 6 2 4 7 Target 1: Delete Node 3 • Node 3 has 2 children (2, 4) • Find successor in right subtree • Successor is 4 (no left child) • Copy 4 into 3, delete leaf 4 2. After Deleting 3 5 4 6 2 7 Target 2: Delete Root 5 • Root 5 has two children (4, 6) • Successor in right subtree is 6 • Copy 6 into root position • 6 has right child 7 (single-child) 3. Final State (Root 6) 6 4 7 2 BST Invariant Preserved • Node 6 replaces root 5 • Node 7 shifts up via single-child • Final structure: 6, 4, 7, 2 • All left < parent < right rules met
Tracing Two Successive Deletions in Our BST diagram
Practice

Practice Deleting a Two-Child Node and Root From Our BST

Phase 4: Practice

Now it is time to test your mental model against our locked working example. Recall our initial BST: root 5, with left subtree 3 (having children 2 and 4) and right subtree 6 (having right child 7). In the previous phase, we walked through deleting node 3 (which had two children) and then deleting the root node 5.
To ensure you can execute these structural surgeries on your own, answer the following scenario-based task. Do not skip the intermediate states; trace how pointers shift when the successor is pulled upward.
Practice Question:
Given our starting BST structure (root 5, left 3 with 2 and 4, right 6 with 7), write out the exact sequence of steps and the final tree structure when you perform only the deletion of node 3 first, and then immediately attempt to delete the new root. What is the value of the successor chosen when removing node 3, and where does it end up?
a.Successor is 4, which replaces 3; the new tree root is still 5 with left child 4 (2 and null).
b.Successor is 2, which replaces 3; the new tree root becomes 2.
c.Successor is 6, which immediately replaces the root 5.
Try this: BST initial state: 5 -> left: 3 (2, 4), right: 6 (null, 7).
Task: Trace deletion of 3, then deletion of 5.
Apply

Applying BST Deletion Patterns to Root Deletion with an Only-Left Child

Phase 5: Applying the Pattern to a Variant Tree

Now that you have traced deleting node 3 and root 5 from our original BST 5, 3, 6, 2, 4, null, 7, let us test your transfer of these rules on a structurally altered tree. Suppose your starting tree is modified to have no right subtree on node 5, or you need to delete a node whose right subtree is entirely single-valued.
Consider a BST with keys 8, 3, 10, 1, 6, null, 14. You are asked to delete root 8, and then immediately delete node 3.
When deleting root 8, it possesses both a left child (3) and a right child (10). Following the two-child deletion pattern established in our working example, you locate the in-order successor in the right subtree — which is 10 (or its leftmost descendant). Since 10 has a right child (14) but no left child, replacing root 8's value with 10 and restructuring the right child requires grafting 14 directly into 10's former position.
Next, you delete node 3, which has two children (1 and 6). Its in-order successor is 6 (or the minimum of its right subtree). Replacing 3 with 6 and removing the original 6 node completes the transformation without violating the BST invariant.
python
class Node:
    def __init__(self, val, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

# Given BST: 8, 3, 10, 1, 6, None, 14
root = Node(8,
            Node(3, Node(1), Node(6)),
            Node(10, None, Node(14))
)

# Question: Write out or trace the resulting tree structure after deleting 8, then deleting 3.

FAQ

What happens when you delete node 3 in the BST [5,3,6,2,4,null,7]?
Node 3 has two children (2 and 4). We replace 3 with its in-order successor (4), remove the duplicate 4 from the right subtree, resulting in [5,4,6,2,null,null,7].
What are the three structural cases of BST deletion?
1.Deleting a leaf node (zero children) by simply removing it.
2.Deleting a node with one child by bypassing it and connecting its parent to its child.
3.Deleting a node with two children by replacing its value with its in-order successor (or predecessor) and deleting that successor node.
Why is the in-order successor used when deleting a node with two children?
The in-order successor (the smallest value in the right subtree) is guaranteed to be larger than all elements in the left subtree and smaller than all other elements in the right subtree, maintaining the valid BST invariant.
What is the time complexity of deleting a node in a BST?
The time complexity is O(h), where h is the height of the tree. In a balanced BST, this is O(log n), but in a skewed tree, it can degrade to O(n).

Keep learning