Week 6 Flashcards

1
Q

Red Black Tree Rules - type of BST

A
  1. Root is always black
  2. Each node is colored black or red
  3. A null node is colored black –> every new node must be inserted red
  4. every red node has two black noeds
  5. every path from ANY node to ANY of its descendant null node must have the same number of black nodes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

VAL vs red-black trees

A

red-black trees are less-perfectly balanced. However, they generally need fewer rotations during insertion/deletion, which makes red-black tree superior for growing or shrinking a tree, but less efficient for searching.

Both O(log n) time complexity

AVL might have greater height and use more memory than Red Black Trees

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

VAL self-balancing BST

A

Uses balance factor (absolut delta between height of left and right subtree).
Balanced if this delta is smaller equal to one for every node.

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

How to rebalance AVL

A

Start from the lowest unbalanced tree.
Label the three nodes, starting from the unbalanced one.
Rearrange.
Check balance factor of ancestor

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

Condition that must be fulfilled such that tree operations are log n

A

Tree must be balanced

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