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 90, 81, 73, 63 and 5, in that order. How many comparisons do the five puts make in all?
the answer, and why
the answer is A
90 is the top, 0. 81 meets 90, 1. 73 meets 90 and 81, 2, then turn right at 90: 81 moves up. 63 meets 81 and 73, 2. 5 meets 81, 73 and 63, 3, then turn right at 73. That is 8.
if you chose another
BThat is the plain tree's count. With no turns, each number meets every number before it.
CThat is middle first's, the cheapest order of five; here 73 meets 90 and 81 before the tree turns.
DThat counts one comparison a put, but later puts go deeper.
An empty AVL tree puts in 19, 95 and 43. How many turns does it make?
the answer, and why
the answer is D
43 hangs left of 95, below 19. 19's right side is 2 levels high and leans inwards. So it turns right at 95, then left at 19: 2 turns, and 43 ends on top.
if you chose another
AOne turn, left at 19, would put 95 on top with 19 below it and 43 below 19, still two levels apart.
B19'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.