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 67, 52, 37, 19 and 9, in that order. How many comparisons do the five puts make in all?
the answer, and why
the answer is A
67 is the top, 0. 52 meets 67, 1. 37 meets 67 and 52, 2, then turn right at 67: 52 moves up. 19 meets 52 and 37, 2. 9 meets 52, 37 and 19, 3, then turn right at 37. 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 37 meets 67 and 52 before the tree turns.
DThat counts one comparison a put, but later puts go deeper.
An empty AVL tree puts in 17, 84 and 62. How many turns does it make?
the answer, and why
the answer is B
62 hangs left of 84, below 17. 17's right side is 2 levels high and leans inwards. So it turns right at 84, then left at 17: 2 turns, and 62 ends on top.
if you chose another
AOne turn, left at 17, would put 84 on top with 17 below it and 62 below 17, still two levels apart.
C17'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.