GATE | GATE CS 2019 | Question 49
Consider the following statements:
- I. The smallest element in a max-heap is always at a leaf node.
- II. The second largest element in a max-heap is always a child of the root node.
- III. A max-heap can be constructed from a binary search tree in Θ(n) time.
- IV. A binary search tree can be constructed from a max-heap in Θ(n) time.
Which of the above statements is/are TRUE?
(A) II, III and IV
(B) I, II and III
(C) I, III and IV
(D) I, II and IV
Explanation: Statement (I) is correct. In a max heap, the smallest element is always present at a leaf node. So we need to check for all leaf nodes for the minimum value. Worst case complexity will be O(n)
12 / \ / \ 8 7 / \ / \ / \ / \ 2 3 4 5
Statement (II) is also correct, otherwise it will not satisfy max-heap property.
Statement (IV) is false, because construction of binary search tree from max-heap will take O(nlogn) time.
So, option (B) is correct.