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 97, 76, 72, 26 and 8, in that order. How many comparisons do the five puts make in all?
the answer, and why
the answer is D
97 is the top, 0. 76 meets 97, 1. 72 meets 97 and 76, 2, then turn right at 97: 76 moves up. 26 meets 76 and 72, 2. 8 meets 76, 72 and 26, 3, then turn right at 72. 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 72 meets 97 and 76 before the tree turns.
CThat counts one comparison a put, but later puts go deeper.
An empty AVL tree puts in 25, 60 and 41. How many turns does it make?
the answer, and why
the answer is A
41 hangs left of 60, below 25. 25's right side is 2 levels high and leans inwards. So it turns right at 60, then left at 25: 2 turns, and 41 ends on top.
if you chose another
BOne turn, left at 25, would put 60 on top with 25 below it and 41 below 25, still two levels apart.
C25'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.