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 heap's own run on the numbers shown.
choose one
1question 1
The heap drawn was made by putting in 74, 69, 81, 88 and 22; its letters show the order each number came in. Put in 18. What is the row then?
the answer, and why
the answer is A
18 goes in at place 6, under 81. It is smaller, so they swap. Now under 22, it is smaller again, so they swap. At the top, it stays.
if you chose another
BThat stops after one swap, but 18 is still smaller than 22 above it.
CThat leaves 18 where it was put, under 81, which is bigger.
DThat is the whole row in order. A heap only swaps 18 up its way to the top.
How many comparisons do these operations make on an empty heap? 66, 59, 68, 47, then one take.
the answer, and why
the answer is B
66 compares nothing. 59 compares with 66 and climbs to the top. 68 compares with 59 and stays. 47 climbs past 66 and 59, two. The take moves 66 to the top, which meets 59 and 68, two more. 66 swaps below 59, has nothing under it, and stops.
if you chose another
AThat counts the puts only. The take compares too.
CThat counts a comparison each time a number is at the top, but nothing is above it to compare with.
DThat counts one comparison for the take. 66 meets both children of the top.