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