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