Consider the following array of elements: 89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100. What is the minimum number of interchanges needed to convert it into a max-heap?
A2
B3
C5
D4
Correct answer: B
Explanation
Taking the intended array 89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100 (the digits are garbled in the paper), building a max-heap needs 3 swaps: 15↔100, 50↔100 and 89↔100.