• retagged by
19,471 views
30 30 votes

​​​​​An array $[82,101,90,11,111,75,33,131,44,93]$ is heapified. Which one of the following options represents the first three elements in the heapified array?

  1. $82,90,101$
  2. $82,11,93$
  3. $131,11,93$
  4. $131,111,90$

3 Answers

25 25 votes

1. Heapify node with value 111. Nothing changes as max-heap property is already satisfied.

2. Heapify node with value 11. Now 11 is swapped with 131 so that max-heap property is satisfied. (blue colored text in image).

3. Heapify node with value 90. Nothing changes as max-heap property is already satisfied.

4. Heapify node with value 101. Now 101 is swapped with 131 so that max-heap property is satisfied. (red colored text in image)

5. Heapify node with value 82. Now 82 is swapped with 131, then 82 is swapped with 111, then 82 is swapped with 93 so that max-heap property is satisfied. (green colored text in image)

Final array - $[131, 111, 90, 101, 93, 75, 33, 11, 44, 82]$

Answer - D

5 5 votes
This can be solved without full heapification.

Observe that in a min-heap the first element (The root) is the smallest. Since none of the options present that case, it is a max heap, hence first element has to be 131. Only option C and D remains.

Option C is impossible because it means the smallest element is in the second (or third level), that will violate the heap property if you try to build other levels.

Even if we assume that 11 is a leaf in one of the subtrees at the 2nd level, even if we try to heapify down the other subtree, we will not be able to place 111 anywhere because 93 will always be an ancestor of it.

So option D makes sense.
Answer:
Position:
Show:

Related questions

2 2 votes
4 answers 4 answers
1.6k
1.6k views
Bikram asked Oct 4, 2016
1,585 views
Is an array that is sorted in decreasing order a max-heap?always yesalways nosometimes onlyyes but not in presence of duplicates
3 3 votes
3 3 answers
1.6k
1.6k views
admin asked Sep 28, 2024
1,593 views
Worst case time complexity of heap sort for $n$ elements?$O(n\log n)$$O(\log n)$$O({n}^2)$$O(n)$
0 0 votes
1 1 answer
1.0k
1.0k views
admin asked Jul 28, 2023
1,044 views
Consider the following statements about heap sort algorithm:The MAX-HEAPIFY procedure which runs in $\mathrm{O} \lg (n)$ time, is the key to maintaining the max heap prop...
162 162 votes
11 answers 11 answers
44.5k
44.5k views
Arjun asked Sep 24, 2014
44,460 views
The number of elements that can be sorted in $\Theta(\log n)$ time using heap sort is$\Theta(1)$$\Theta(\sqrt{\log} n)$$\Theta(\frac{\log n}{\log \log n})$$\Theta(\log n)...