Machine-translated by Google. Questions are authored in English.
Top

Discussion

An array [82, 101, 90, 11, 111, 75, 33, 131, 44, 93] is heapified. Which one of the following options represents the first three elements in the heapified array?

  • A.82, 90, 101
  • B.82, 11, 93
  • C.131, 11, 93
  • D.131, 111, 90

Answer: D

The first three elements are 131, 111, 90.

Heapify here builds a max-heap bottom-up, sifting down from the last internal node (index 4, value 111) to the root:

  • 111 already exceeds its child 93.
  • 11 swaps with its larger child 131.
  • 90 stays above 75 and 33.
  • 101 swaps with 131, then stays above 11 and 44.
  • 82 swaps with 131, then with 111, then with 93.

The result is [131, 111, 90, 101, 93, 75, 33, 11, 44, 82]. The root must be the maximum, 131, which rules out the options starting with 82. Option C puts 11 at index 1, above larger elements such as 101, which a max-heap forbids.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.