Red-black BST' Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a RB tree?

A

Encoding of BST by adding extra information to create 3-nodes.

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

What are the red and black links and what are their properties?

A
  • Red links bind two 2-nodes to represent 3-nodes
  • Black links bind together 2-3 trees
    Red links lean left and no node can have two connected.
    The tree has perfect black balance.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is left and right rotation?

A

Used to correct right-leaning links or links in a row.
* If right leaning, use left rotation to return link to a node that is the root of a RD BST for the same set of keys whose left link is red (Switching from smaller at root to larger at root. Becomes left child of right child.)
* Right rotation: Becomes right child of left child

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

How do we insert into a single 2-node?

A

Insert into key and perform rotation if necessary.

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

How do we insert into a 2-node at the bottom?

A
  • If parent is 2-node, do the same as with 2-node insertion
  • Parent will become a 3-node.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the 3 cases for insertion into a 3-node?

A

If inserting key is larger:
* Atttach to right
* Make balance with middle key at root
* Flip colours from red to black

If key smaller:
* Goes on left
* Reduce to previous case by rotating top link to the right

If key between:
* Right leaning below a left leaning
* Reduce to previous by rotating right link to left

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

How do we insert a 3-node at the bottom of the tree?

A

Same cases arise as above.

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

What is the height of a red black BST?

A

No more than 2lg N

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