Skip to content
Data Structures and Algorithms / Trees, Heaps, and Ordered Search

Derivation — Insertion and Deletion in Red-Black Trees

The previous lesson stated the red-black properties and claimed that rotations restore them cheaply after any mutation, without showing the mechanism. This derivation works through the case analysis for insertion fix-up in full (deletion fix-up is structurally similar but longer; it is summarised at the level CLRS itself uses for a second pass) and shows why the case analysis terminates in O(log⁡n)O(\log n) rotations — in fact at most O(1)O(1) actual rotations, with O(log⁡n)O(\log n) colour flips.

In this lesson

  1. Insertion: where the violation can occur
  2. Why this terminates and costs O(log⁡n)O(\log n)
  3. Deletion fix-up, at a glance

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or explore the curriculum.