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