Data Structures & AlgorithmsModerateProduct-company MCQ pattern

Seven distinct keys are stored in a max-heap in a 0-indexed array. Which statement is correct?

  1. A. The smallest key is always at index 6
  2. B. The second largest key can be at any index from 1 to 6
  3. C. The smallest key can be at any index from 1 to 6
  4. D. The smallest key can only be at index 3, 4, 5 or 6, and the second largest only at index 1 or 2

Correct answer: D. The smallest key can only be at index 3, 4, 5 or 6, and the second largest only at index 1 or 2

The minimum cannot have a child (its child would have to be smaller), so it is one of the 4 leaves, indices 3–6, not necessarily the last one. The second largest has only the root above it, so it must be a child of the root: index 1 or 2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic