Course contentsShow
← Computer Science
Lesson 508 of 2,87212. Binary Search TreesFree lesson

BST Deletion: Leaf Node Case

Delete a leaf node by simply removing it and updating its parent's pointer to null.

BST Deletion: Leaf Node Case

What you'll learn: How to delete the simplest type of node in a Binary Search Tree—a leaf with no children.


The Simplest Deletion Scenario

When deleting a node from a BST, the easiest case is when the node you want to remove is a leaf node—a node with no left or right children. Think of it like pruning the tip of a tree branch: you simply snip it off, and nothing else is affected below it.

How It Works

To delete a leaf node:

  1. Find the node you want to delete (using BST search)
  2. Identify its parent node
  3. Update the parent's pointer (either left or right) to null
  4. The leaf node is now disconnected and can be garbage collected

For example, if you have a BST with values [5, 3, 7, 1, 4] and you want to delete the leaf 4:

  • Node 4 is the right child of node 3
  • Set 3.right = null
  • Node 4 is now removed

Why This Is Simple

A leaf node has no dependents—no children that need to be relocated. You're not disrupting any subtrees or violating the BST property. The parent simply "forgets" about this child, and the rest of the tree remains valid.

Special Case: Deleting the Root

If the tree has only one node (the root, which is also a leaf), you simply set the root pointer to null, leaving you with an empty tree.


Key Takeaway: Deleting a leaf node from a BST is straightforward—just update the parent's pointer to null, disconnecting the leaf without affecting the BST structure or invariant.