liveBook · Manning

Chapter 8: Balanced trees

What you will learn in chapter 8 of Grokking Algorithms, Second Edition

The chapter introduction motivates balanced trees as a way to improve tree performance when other data structures fall short.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction motivates balanced trees as a way to improve tree performance when other data structures fall short.

Key terms: arrays, linked lists, binary trees, balanced tree, worst-case scenario

8.1 A balancing act

This section contrasts fast searching in a sorted array with fast insertion in a linked list, motivating a way to get both advantages.

Key terms: binary search, sorted array, linked list, O(log n), O(n)

8.2 Improving insertion speed with trees

This section introduces binary search trees as a way to seek fast searches and insertions, then shows how their ordering rule guides a search.

Key terms: sorted array, linked lists, balanced binary search tree (BST), binary search tree, BST, node, left child, right child, subtree, root node

8.3 Shorter trees are faster

This section shows why a binary search tree’s height determines search speed and why repeatedly adding larger values can produce a slow, one-sided tree.

Key terms: height, worst-case tree, best-case tree, O(n), O(log n), BST, balanced BST

8.4 AVL trees: A type of balanced tree

Introduces AVL trees as self-balancing binary search trees that use rotations to keep their height O(log n).

Key terms: AVL trees, self-balancing BST, O(log n) height, rotations

8.5 Rotations

This section shows how left rotations rearrange nodes to restore balance in an AVL tree.

Key terms: rotation, left rotation, root node, AVL trees, balanced, unbalanced

8.6 How does the AVL tree know when it’s time to rotate?

The section explains how an AVL tree detects imbalance after insertion and why a balanced BST supports fast searches and insertions.

Key terms: height, balance factor, rebalance, ancestors, rotation, balanced BST, AVL tree, O(log n), insertion

8.7 Splay trees

This section explains how splay trees make recently accessed nodes faster to find and why their overall search performance can be good despite slow individual searches.

Key terms: splay trees, root, recently, balanced, rotate, O(log n), linear time, O(n log n)

8.8 B-trees

Introduces B-trees as a generalization of binary search trees whose nodes can hold multiple keys and have more than two children.

Key terms: B-trees, binary trees, nodes, children, keys

8.9 What is the advantage of B-trees?

Explains why B-trees can retrieve data efficiently and describes their key ordering and node structure.

Key terms: B-trees, seek time, nodes, B-tree, BST, keys, children, root node

8.10 Recap

This recap summarizes the performance benefits of balanced binary search trees and how AVL trees and B-trees pursue them.

Key terms: balanced binary search trees (BSTs), Big O, height, AVL trees, balanced BST, rotation, B-trees, generalized BSTs, keys, child nodes

Concepts explained in this chapter

← Chapter 7: Trees Chapter 9: Dijkstra’s algorithm →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.