Question

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)\Theta(n) time
IV. A binary search tree can be constructed from a max-heap in Θ(n)\Theta(n) time

Which of the above statements are TRUE?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2019 answer key

Solution

Evaluate each statement concerning max-heaps and binary search trees.

Statement I: In a max-heap, every node is greater than or equal to its children (A[parent]≥A[child]A[\text{parent}] \ge A[\text{child}]). If the smallest element were at an internal node, its children would have to be smaller than it, contradicting that it is the smallest element. Thus, the smallest element must be at a leaf node. (TRUE)

Statement II: The root holds the maximum element. The second largest element cannot be dominated by any element other than the root. Therefore, it must be located directly at one of the children of the root (index 1 or 2). (TRUE)

Statement III: To construct a max-heap from a BST of nn elements, we can extract the nn elements via inorder traversal in Θ(n)\Theta(n) time and place them into an array. Then, running Floyd's build_max_heap on the array takes Θ(n)\Theta(n) time. The total time is Θ(n)\Theta(n). (TRUE)

Statement IV: If a BST could be constructed from a max-heap in Θ(n)\Theta(n) time, then since an inorder traversal of a BST outputs elements in sorted order in Θ(n)\Theta(n) time, we would be able to sort an arbitrary array in Θ(n)\Theta(n) comparison time (build max-heap in Θ(n)\Theta(n), construct BST in Θ(n)\Theta(n), traverse BST in Θ(n)\Theta(n)). This contradicts the well-established Ω(nlog⁡n)\Omega(n \log n) lower bound for comparison-based sorting. Hence, a BST cannot be constructed from a max-heap in Θ(n)\Theta(n) time in general. (FALSE)

Thus, statements I, II, and III are TRUE.

Final answer

A

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2019 Computer Science and Information Technology (CS)
Question
50 of 65, printed as CS Q.40
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.