Also called Self-balancing binary search tree and Adelson-Velsky and Landis tree.
fresh numbers
The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from avl tree's own run on the numbers shown.
choose one
1question 1
An empty AVL tree puts in 87, 57, 37, 34 and 11, in that order. How many comparisons do the five puts make in all?
the answer, and why
the answer is C
87 is the top, 0. 57 meets 87, 1. 37 meets 87 and 57, 2, then turn right at 87: 57 moves up. 34 meets 57 and 37, 2. 11 meets 57, 37 and 34, 3, then turn right at 37. That is 8.
if you chose another
AThat is the plain tree's count. With no turns, each number meets every number before it.
BThat is middle first's, the cheapest order of five; here 37 meets 87 and 57 before the tree turns.
DThat counts one comparison a put, but later puts go deeper.
An empty AVL tree puts in 12, 64 and 14. How many turns does it make?
the answer, and why
the answer is D
14 hangs left of 64, below 12. 12's right side is 2 levels high and leans inwards. So it turns right at 64, then left at 12: 2 turns, and 14 ends on top.
if you chose another
AOne turn, left at 12, would put 64 on top with 12 below it and 14 below 12, still two levels apart.
B12's two sides are 2 levels apart, so it must turn.
CA put mends at most once, with a single turn or a double, so 2 turns at most.