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 89, 71, 57, 44 and 25, in that order. How many comparisons do the five puts make in all?
the answer, and why
the answer is A
89 is the top, 0. 71 meets 89, 1. 57 meets 89 and 71, 2, then turn right at 89: 71 moves up. 44 meets 71 and 57, 2. 25 meets 71, 57 and 44, 3, then turn right at 57. 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 57 meets 89 and 71 before the tree turns.
DThat counts one comparison a put, but later puts go deeper.
An empty AVL tree puts in 18, 65 and 52. How many turns does it make?
the answer, and why
the answer is C
52 hangs left of 65, below 18. 18's right side is 2 levels high and leans inwards. So it turns right at 65, then left at 18: 2 turns, and 52 ends on top.
if you chose another
AOne turn, left at 18, would put 65 on top with 18 below it and 52 below 18, still two levels apart.
B18's two sides are 2 levels apart, so it must turn.
DA put mends at most once, with a single turn or a double, so 2 turns at most.