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 82, 51, 14, 5 and 3, in that order. How many comparisons do the five puts make in all?
the answer, and why
the answer is B
82 is the top, 0. 51 meets 82, 1. 14 meets 82 and 51, 2, then turn right at 82: 51 moves up. 5 meets 51 and 14, 2. 3 meets 51, 14 and 5, 3, then turn right at 14. That is 8.
if you chose another
AThat 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 14 meets 82 and 51 before the tree turns.
DThat counts one comparison a put, but later puts go deeper.
An empty AVL tree puts in 41, 82 and 49. How many turns does it make?
the answer, and why
the answer is D
49 hangs left of 82, below 41. 41's right side is 2 levels high and leans inwards. So it turns right at 82, then left at 41: 2 turns, and 49 ends on top.
if you chose another
AOne turn, left at 41, would put 82 on top with 41 below it and 49 below 41, still two levels apart.
B41'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.