Consider a binary max-heap implemented using an array. Which among the…
2025
Consider a binary max-heap implemented using an array. Which among the following arrays represents a binary max-heap ?
- A.
25,12,16,8,10,13,14
- B.
25,12,16,13,10,8,14
- C.
25,14,12,13,10,8,16
- D.
25,14,12,13,10,16,8
Attempted by 78 students.
Show answer & explanation
Correct answer: A
A binary max-heap requires that every parent node be greater than or equal to its children. In an array representation, for a node at index i (0-based), the left child is at 2i+1 and the right child is at 2i+2. Option C: Index 0=25 (children at 1,2 are 14,12 - OK). Index 1=14 (children at 3,4 are 13,10 - OK). Index 2=12 (children at 5,6 are 8,16 - VIOLATION since 12<16). This suggests Option C is incorrect. Option B (25,12,16,13,10,8,14): Index 0=25 (children 12,16 - OK). Index 1=12 (children 13,10 - VIOLATION since 12<13). Option D (25,14,12,13,10,16,8): Index 0=25 (children 14,12 - OK). Index 1=14 (children 13,10 - OK). Index 2=12 (children 16,8 - VIOLATION since 12<16). Option A (25,12,16,8,10,13,14): Index 0=25 (children 12,16 - OK). Index 1=12 (children 8,10 - OK). Index 2=16 (children 13,14 - OK). This satisfies all max-heap properties. The correct answer should be Option A