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 18, 54, 70, 57 and 96; its letters show the order each number came in. Put in 15. What is the row then?
the answer, and why
the answer is D
15 goes in at place 6, under 70. It is smaller, so they swap. Now under 18, it is smaller again, so they swap. At the top, it stays.
if you chose another
AThat stops after one swap, but 15 is still smaller than 18 above it.
BThat leaves 15 where it was put, under 70, which is bigger.
CThat is the whole row in order. A heap only swaps 15 up its way to the top.
How many comparisons do these operations make on an empty heap? 58, 40, 85, 6, then one take.
the answer, and why
the answer is A
58 compares nothing. 40 compares with 58 and climbs to the top. 85 compares with 40 and stays. 6 climbs past 58 and 40, two. The take moves 58 to the top, which meets 40 and 85, two more. 58 swaps below 40, has nothing under it, and stops.
if you chose another
BThat 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. 58 meets both children of the top.