Open In App

GATE | GATE IT 2006 | Question 44

Like Article
Like
Save
Share
Report

Which of the following sequences of array elements forms a heap?

(A)

{23, 17, 14, 6, 13, 10, 1, 12, 7, 5}

(B)

{23, 17, 14, 6, 13, 10, 1, 5, 7, 12}

(C)

{23, 17, 14, 7, 13, 10, 1, 5, 6, 12}

(D)

{23, 17, 14, 7, 13, 10, 1, 12, 5, 7}



Answer: (C)

Explanation:

  When they are asking for heap, by default it\’s max heap. Basic Requirement: Array representation of binary tree Starting from basics lets first understand heap trees We have 2 types of heap – Min heap and Max heap In Min heap the parent is always smaller than its children and in Max heap parent is always greater than its children. \"heap\" Looking at the options we can tell that which tree is Max heap tree. Now consider each option one by one and draw a tree \"max-heap\" From options it is clear that only option C satisfies the Max heap tree property. 

Hence Option(C) is the correct answer.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads