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