The GATE Grind

GATE 2023 CS – Question 12

Programming and Data Structures · Binary Heaps · 1 mark · Multiple choice

Which one of the following sequences when stored in an array at locations A[1],...,A[10] forms a max-heap?

  1. 23, 17, 10, 6, 13, 14, 1, 5, 7, 12
  2. 23, 17, 14, 7, 13, 10, 1, 5, 6, 12
  3. 23, 17, 14, 6, 13, 10, 1, 5, 7, 15
  4. 23, 14, 17, 1, 10, 13, 16, 12, 7, 5

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 23, 17, 14, 7, 13, 10, 1, 5, 6, 12

Explanation

Check A[i] ≥ A[2i], A[2i+1]. (A) fails at 10 < 14. (C) fails at 13 < 15. (D) fails at 1 < 12. (B) satisfies all parent-child relations.