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 binary search tree's own run on the numbers shown.
choose one
1question 1
An empty tree puts in 46, 33, 90, 11, 8 and 31, in that order. How many comparisons do the six puts make in all?
the answer, and why
the answer is C
Each put meets every number on its way down from the top: put by put, 0 + 1 + 1 + 2 + 3 + 3, 10 in all.
if you chose another
AThat counts every number before each put, as if the tree were a path.
BThat counts 1 comparison a put after the first, but some puts go deeper.
An empty tree puts in 19, 4, 71, 33 and 77, then takes 19 out. How many comparisons do the six operations make?
the answer, and why
the answer is A
The puts make 0, 1, 1, 2 and 2, which is 6. The take meets 19 at the top, 1. 33, the smallest number to its right, takes its place, reached by following links with no comparison. That is 7.
if you chose another
BThat leaves out the take's comparison with 19.
CThat counts the walk to 71 and 33 as 2 comparisons; it only follows links.
DThat counts the walk to 33 as 1 comparison; it only follows links.