UGC-NET Jul 2016 · Arrays & Matrix Representation

MCQ · 2 marks · Problem PROG-DSTR-0031

Which one of the following array represents a binary max-heap?
  1. A
    [26, 13, 17, 14, 11, 9, 15]
  2. B
    [26, 15, 14, 17, 11, 9, 13]
  3. C
    [26, 15, 17, 14, 11, 9, 13]
  4. D
    [26, 15, 13, 14, 11, 9, 17]

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solution\[\boxed{A[i]\ge A[2i]\ \text{and}\ A[i]\ge A[2i+1]\ (1\text{-indexed})}\](A) Node 13 (index 2) has child 14 — violates.(B) Node 15 (index 2) has child 17 (index 4) — violates.(C) 26 \(\ge\) 15, 17; 15 \(\ge\) 14, 11; 17 \(\ge\) 9, 13 — a valid max-heap.(D) Node 13 (index 3) has child 17 — violates.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com