Which one of the following array represents a binary max-heap?
(A) [26, 13, 17, 14, 11, 9, 15]
(B) [26, 15, 14, 17, 11, 9, 13]
(C) [26, 15, 17, 14, 11, 9, 13]
(D) [26, 15, 13, 14, 11, 9, 17]
Answer: (C)
Explanation: For max heap we will compare parent node(i) with its left-child(2 * i) and right-child(2 * i + 1):
- In first option node(2)
- In second option node node(2)
- In third option there is no violation.
- In fourth option node(3)
So, option (C) is correct.
Quiz of this Question