Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 2

From Binary Search to Balanced Trees: Hibbard Deletion and Beyond

Recommended resources

Welcome back! In our previous lesson, we established a clear motivation for binary search trees by exposing the performance dilemma of simpler data structures: unsorted lists are fast for updates but slow for searches, while sorted arrays are fast for searches but slow for updates. We concluded with the need for a dynamic structure that could offer logarithmic time for both.

Today, we'll dive into the history of how computer scientists solved this problem. As you requested, we will explore the origins of the Binary Search Tree, tracing its development from the core idea of binary search to the first attempts at dynamic operations and the crucial discoveries that shaped its evolution. This lesson will cover the conceptual leap to a tree structure, early algorithms for deletion, and why those first attempts highlighted the need for the balanced variants that are ubiquitous in software engineering today.

From Binary Search to a Tree Structure

The core idea behind a Binary Search Tree (BST) is a direct, elegant generalization of binary search on a sorted array. In an array, we find the middle element to divide the search space. The problem, as we saw, is that inserting or deleting an element requires physically shifting large blocks of memory, an operation.

The breakthrough was to replace the rigid, contiguous array with a flexible, node-based structure of pointers. Imagine taking a sorted list of numbers and picking the median as the "root." All numbers to its left belong to a left group, and all numbers to its right belong to a right group. Instead of just having a "next" pointer like a linked list, this root node has two: one pointing to the median of the left group, and one pointing to the median of the right group. Applying this logic recursively gives birth to a tree.

The following reading provides an excellent illustration of this transformation.

Exploring binary search trees

This article visualizes how the recursive application of a "search from the middle" strategy on a linked sequence naturally gives rise to the tree structure.

Please read the section "Binary search trees". Focus on the conceptual jump from a linear sequence to a tree rooted at the median element. The diagrams in Figures 3 and 4 are particularly helpful for visualizing this.

This node-based structure preserves the divide-and-conquer power of binary search while solving the update problem. To insert a new value, we no longer need to shift elements. We simply traverse the tree to find the correct leaf position and attach a new node. This operation takes time proportional to the height of the tree, , a promising improvement over the array's .


The Deletion Dilemma: Hibbard's Algorithm

While insertion is relatively straightforward, deleting a node is far more complex. Deleting a leaf is easy. Deleting a node with one child is also simple: we can just "splice" it out by linking its parent to its child. But what happens when we need to delete a node that has two children? Removing it would break the tree into two disconnected subtrees.

This challenge was one of the first major hurdles in the development of BSTs. In 1962, Thomas Hibbard proposed a clever solution that has become a classic algorithm. The idea is to replace the deleted node's key and value with that of its in-order successor—the smallest key in its right subtree. This successor is guaranteed to have at most one child (its right child), making it easy to remove from its original position.

The following resources describe this early approach to deletion and its historical significance.

Exploring binary search trees

This text provides a clear explanation and illustration of the deletion strategy.

Focus on the section on Deletion, which introduces the problem and Hibbard's 1961 algorithm. Figure 6 in the article provides a great visual of how the in-order successor (or predecessor) is used to fill the gap.

CMSC 420: Lecture 4 Binary Search Trees

This document adds fascinating historical context about the discovery and analysis of Hibbard's algorithm.

Read the paragraph that starts here. Then, pay close attention to the footnote beginning with "There is an interesting history regarding this question." It gives a great sense of how the understanding of this algorithm evolved over decades.


A Subtle Flaw and the Need for Balance

Hibbard's algorithm correctly maintains the BST's ordering property. For years, it was believed to be a complete solution. However, a subtle flaw lurks beneath the surface. As noted in the readings, the algorithm is asymmetric. By consistently choosing the successor from the right subtree, it introduces a structural bias.

Over a long sequence of random insertions and deletions, this bias causes the tree to become unbalanced. Left subtrees tend to become deeper than right subtrees. This was a major, non-obvious discovery. While a perfectly balanced tree has a height of , researchers like Culberson and Munro showed that a tree undergoing many Hibbard deletions would degrade, with its average height converging to .

This is a critical point in the history of data structures. The promise of performance for BSTs depends entirely on the tree's height, . If the tree degenerates into a shape that is tall and skinny—in the worst case, a linked list—its performance degrades to . The professor in the MIT lecture you watched previously alluded to this exact problem.

Lecture 5: Binary Search Trees, BST Sort

Let's revisit a key moment from the MIT lecture where this very issue is raised.

Watch the clip from the bad news, where the lecturer demonstrates how a sorted insertion sequence creates a degenerate tree, turning it into a linked list and undermining the efficiency of the structure.

The structural decay caused by biased deletion, combined with the worst-case performance from ordered insertions, made it clear that simply hoping for a balanced tree wasn't enough. A mechanism was needed to enforce balance.

This realization spurred a new wave of innovation, leading to the invention of self-balancing binary search trees. These variants—which you'll encounter frequently in production code and system design interviews—add specific rules and perform re-balancing operations (called rotations) during insertions and deletions to guarantee that the tree's height remains logarithmic.

The first such structure was the AVL tree, invented in 1962 by Georgy Adelson-Velsky and Evgenii Landis. A later, and now more common, variant is the Red-Black tree, developed by Leo J. Guibas and Robert Sedgewick in 1978. Java's TreeMap, for example, is implemented using a Red-Black Tree.


Conclusion

In this lesson, we traced the early history of the Binary Search Tree, fulfilling your interest in its developmental context. We've seen how:

  • The BST emerged as a way to apply the principles of binary search to a dynamic, pointer-based structure, overcoming the update limitations of a sorted array.
  • Early algorithms like Hibbard deletion provided a working solution for dynamic updates but contained a subtle, asymmetric bias.
  • This bias, along with worst-case insertion orders, was found to degrade the tree's structure over time, with height growing towards or even , compromising the desired performance.
  • This discovery highlighted a critical need for mechanisms to control the tree's height, leading directly to the invention of self-balancing variants like AVL trees and Red-Black trees.

This historical journey gives you a deep appreciation for why so much of the theory and implementation of BSTs revolves around maintaining balance.

In the next lesson, we will step back from the advanced topic of balancing and focus on the absolute foundation of the BST. We will formally define the strict ordering invariant—the simple, powerful rule that must hold true for a tree to be a valid BST and which underpins every algorithm we will write.