Lecture 5 - Red-Black Trees Flashcards

1
Q

What are red-black trees?

A

balanced binary search trees with tree height O(logn) where each node has a bit indicating red or black.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Whats the runtime of most operations in RBT?

A

O(logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 5 properties of a RBT?

A
  1. Every node is either red or black
  2. The root is black
  3. All leaves (nil) are black.
  4. If a node is red, then its children are black (no 2 consecutive red nodes)
  5. For each node, all paths from node to descendant leaves contain the same number of black nodes (same black height)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Black-height of a node x?

A

The number of black nodes on the path from root to leaf, without counting x.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the relation between Black height and height.

A

bh <= h <= bh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Prove that any node x with height h(x) has a black-height bh(x) ≥ h(x)/2.

A

Proof: By RB property 4, ≤ h / 2 nodes on the path from

the node to a leaf are red. Hence ≥ h/2 are black.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Prove: The subtree rooted at any node x contains ≥ 2^(bh(x)) – 1 internal nodes.

A

Proof: By induction on height of x.
• Base Case: Height h(x) = 0 -> x is a leaf -> bh(x) = 0.
Subtree has ≥ 2^0–1 = 0 nodes.
• Induction Step:
– Each child of x has height h(x) - 1 and black-height either bh(x) (child is red) or bh(x) - 1 (child is black).
– By ind. hyp., each child has ≥ 2^(bh(x)– 1) – 1 internal nodes.
– Subtree rooted at x has ≥ 2 * (2^(bh(x)– 1)– 1) + 1
= 2bh(x) – 1 internal nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Prove: A red-black tree with n internal nodes has

height at most 2 lg(n+1).

A
  • By lemma 2, n ≥ 2^bh – 1,
  • By lemma 1, bh ≥ h/2, thus n ≥ 2^h/2 – 1.
  • -> h ≤ 2 lg(n + 1).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

State the three lemmas of Red-Black Trees.

A
  1. Any node x with height h(x) has a black-height bh(x) ≥ h(x)/2.
  2. The subtree rooted at any node x contains ≥ 2^(bh(x)) – 1 internal nodes.
  3. A red-black tree with n internal nodes has
    height at most 2 lg(n+1).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the run-time of insert in a RBT?

A

O(logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the maximum amount of rotation needed for each insert in a RBT?

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the differences between AVL and RBT?

A
  • AVL trees are more strictly balanced ⇒ faster search
  • Red Black Trees have less constraints and insert/remove operations require less rotations ⇒ faster insertion and removal
  • AVL trees store balance factors or heights with each node
  • Red Black Tree requires only 1 bit of information per node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly