algorithm-notes
  • Preface
  • Outline
    • Asymptotic-Analysis
    • Divide-and-Conquer (DnC)
      • Overview
      • Multiplication
      • DnC Strategy
      • Master Method
    • Randomization
      • Overview
      • Discrete Probability
      • Randomized Algorithms
      • Reservoir Sampling
    • Sorting
      • Overview
      • Selection Sort
      • Bubble Sort
      • Insertion Sort
      • Shell Sort
      • Merge Sort
      • Heap Sort
      • Quick Sort
      • Non-Comparison Sort
    • Graph Algorithms
      • Overview
      • Minimum Spanning Tree
      • Shortest Path
      • Topological Sort
    • Tree
      • Overview
      • Balanced Search Tree
        • AVL Tree
        • Red-Black Tree
        • B Tree
      • Heap
      • Disjoint Set
      • Threaded Binary Tree
      • Segment Tree
    • Searching
      • Overview
      • Binary Search
      • Graph Search
      • Hash Table
      • String Search
    • Dynamic Programming
      • Overview
      • Fibonacci Numbers
      • LCS problem
    • Greedy Algorithms
      • Overview
Powered by GitBook
On this page

Was this helpful?

  1. Outline
  2. Tree
  3. Balanced Search Tree

Red-Black Tree

PreviousAVL TreeNextB Tree

Last updated 6 years ago

Was this helpful?

is a type of . It adds a bit to stand for the color: RED or BLACK, of each node.

Formal Def:

A is a type of that follows the properties below:

  1. Each node is either RED or BLACK

  2. The root is BLACK

  3. All leaf nodes (NIL) are BLACK

  4. If a node is RED, both of its children are BLACK

  5. Every path from a node to its leaves contains the same number of BLACK nodes (Def: the number of black nodes from a chosen node 𝓍 to a NIL leaf (node 𝓍 is not included) is called the black-height (bh(𝓍)) of such node, the number of black nodes from root to any NIL leaves is the black-height of the total red-black tree)

Height Guarantee

Formal Claim:

For every with 𝓃 nodes, its height 𝒽 ⩽ 2 ⋅ log2 (n + 1).

Proof:

First, there are at least 2bh(x) - 1 number of internal nodes rooted from node x.

By simple induction, the base case: if height of tree x is 0, then there is 20 - 1 = 0; for tree with height more than 0 with both child nodes, there are at least 2bh(x) - 1 - 1 internal nodes for each child node. Therefore, a rooted tree from x has at least 2 * (2bh(x) - 1 - 1) + 1 = 2bh(x) - 1.

Presumably, for a given tree with height 𝒽, any paths leading from root to leaves have at least half of the nodes are black, in other words, the bh(root) ⩾ 𝒽/2; then

n ⩾ 2𝒽/2 - 1, 𝒽 ⩽ 2 log(n+1)

guarantee holds, proof ends.

balanced binary search tree
binary search tree
Red Black Tree
Red Black Tree
red-black tree