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