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