liveBook · Manning

Self-balancing binary search tree

As explained in Grokking Data Structures

A balanced binary search tree is a binary search tree whose height is constrained to remain logarithmic in the number of elements.

A self-balancing binary search tree keeps its height logarithmic in the number of elements. In a height-balanced tree, each node’s left and right subtree heights differ by at most one, and both subtrees are balanced. section 11.19 section 11.20

With height constrained to O(log(n)), a balanced binary search tree provides predictable performance:

  • Search, insertion, deletion, predecessor, successor, minimum, and maximum all take O(log(n)) time. section 11.20
  • It offers the same general ordered-data role as a sorted array, while averaging better performance across the full range of operations. section 11.19
  • Unlike an ordinary BST, it uses balancing strategies to prevent height from growing too large. section 11.19

Common balancing strategies

Randomized heaps provide nondeterministic balance, while red–black trees and 2–3 trees are among the most-used balanced search trees. section 11.19

How Grokking Data Structures covers it

How deep it goes
Defines height balance and logarithmic operation bounds, but defers the detailed mechanics of balancing implementations.
Examples
Names randomized heaps, red–black trees, and 2–3 trees as balancing approaches.
What it assumes
Builds on binary-tree structure, child ordering, and binary search tree rules for left and right subtrees.
What you can do after
Evaluate ordered-data structures using logarithmic bounds and operation-wide performance tradeoffs.
How it connects
Connects binary search trees with binary trees, heaps, sorted arrays, linked lists, red–black trees, and 2–3 trees.

Also explained in

Compare how 3 books explain self-balancing binary search tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Data Structures. The section links point to the parts of the book it draws on.