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 88, 71, 62, 22 and 95; its letters show the order each number came in. Put in 11. What is the row then?
the answer, and why
the answer is D
11 goes in at place 6, under 71. 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
AThat stops after one swap, but 11 is still smaller than 22 above it.
BThat leaves 11 where it was put, under 71, which is bigger.
CThat is the whole row in order. A heap only swaps 11 up its way to the top.
How many comparisons do these operations make on an empty heap? 22, 21, 50, 17, then one take.
the answer, and why
the answer is D
22 compares nothing. 21 compares with 22 and climbs to the top. 50 compares with 21 and stays. 17 climbs past 22 and 21, two. The take moves 22 to the top, which meets 21 and 50, two more. 22 swaps below 21, 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. 22 meets both children of the top.