Which one of the following array elements represents a binary min heap?

Category: QuestionsWhich one of the following array elements represents a binary min heap?
Editor">Editor Staff asked 1 month ago

Which one of the following array elements represents a binary min heap?
 
(a) 12 10 8 25 14 17
 
(b) 8 10 12 25 14 17
 
(c) 25 17 14 12 10 8
 
(d) 14 17 25 10 12 8
 
My enquiry is from Heap topic in section Heap of Data Structures & Algorithms I
 
This question was posed to me in an interview.

1 Answers
Editor">Editor Staff answered 1 month ago

Right option is (b) 8 10 12 25 14 17
 
To explain: A tree is min heap when data at every node in the tree is smaller than or equal to it’s children’ s data. So, only 8 10 12 25 14 17 generates required tree.