Question discussion

Which of the following arrays (1-indexed) represents a valid max-heap?

1756Medium DSSSB TGT Computer Science 0 replies 1 views
0

Which of the following arrays (1-indexed) represents a valid max-heap?

  • A90 70 80 30 85 50 40
  • B90 70 80 30 60 50 40
  • C70 90 80 30 60 50 40
  • D90 70 80 30 60 50 100
Correct answer: B

Explanation

Only C satisfies A[i] ≥ A[2i] and A[i] ≥ A[2i+1] for every node; in A, 85 exceeds its parent 70, in B the root is smaller than its child, and in D 100 exceeds its parent 80.

Discussion 0

Nobody has replied yet. Start the discussion!