Keeping a tree balanced
1.[3p] Why does a rotation preserve the binary search tree property?
Why does a rotation preserve the binary search tree property?
The answer is: The subtree that changes sides already lay between the two rotated keys in value
The answer is: The subtree that changes sides already lay between the two rotated keys in value
The answer is: The subtree that changes sides already lay between the two rotated keys in value
2.[2p] How many pointers does a single rotation have to change, regardless of subtree size?
How many pointers does a single rotation have to change, regardless of subtree size?
3.[3p] Inserting into an AVL node's left child's right subtree needs
Inserting into an AVL node's left child's right subtree needs
The answer is: a double rotation, left at the child then right at the node
The answer is: a double rotation, left at the child then right at the node
The answer is: a double rotation, left at the child then right at the node
4.[3p] The fewest nodes in an AVL tree of height obey with and . What is ?
The fewest nodes in an AVL tree of height obey with and . What is ?
5.[3p] Using , what is the AVL height bound for a million keys?
Using , what is the AVL height bound for a million keys?
6.[2p] A red-black tree gives a tighter height bound than an AVL tree.
A red-black tree gives a tighter height bound than an AVL tree.
The answer is: False
7.[3p] Why do most standard libraries ship red-black trees rather than AVL trees?
Why do most standard libraries ship red-black trees rather than AVL trees?
Select all that apply
The answer is: An insertion needs at most two rotations and a deletion at most three, both constants, Much of the repair is done by recolouring, which is cheaper than pointer surgery, AVL deletion can cascade rotations all the way to the root
8.[3p] A B-tree node holds about 1000 children. How many levels does it take to hold a billion keys?
A B-tree node holds about 1000 children. How many levels does it take to hold a billion keys?
9.[3p] Match each structure to what distinguishes it.
Match each structure to what distinguishes it.
AVL tree
Red-black tree
Treap
Splay tree
every path holds the same black count
subtree heights differ by at most one
a random priority kept in heap order
every accessed node rotated to the root
Show the answer
AVL tree: subtree heights differ by at most one Red-black tree: every path holds the same black count Treap: a random priority kept in heap order Splay tree: every accessed node rotated to the root