edited by
2,382 views
0 0 votes

gate heap sort question

please help me out in solving this question. the solution provided there is not upto the mark

2 Answers

0 0 votes

in heap sort loop runs for n times for every node and in each loop it calls heapify function 1 time 

after 1st iteration largest element is at its place

after 2nd iteration 2nd largest element is at its place

after 3rd iteration  3rd largest element is at its place 

and so on 

in the given output we can see that only last 3 elements are in their position that are 20,23and 25

so heapify would have been called 3 time .So the answer is 3

 

 

0 0 votes
in heap sort loop runs for n times for every node and in each loop it calls heapify function 1 time

after 1st iteration largest element is at its place

after 2nd iteration 2nd largest element is at its place

after 3rd iteration  3rd largest element is at its place

and so on

in the given output we can see that only last 3 elements are in their position that are 20,23and 25

so heapify would have been called 3 time .So the answer is 3
Position:
Show:

Related questions

0 0 votes
0 0 answers
505
505 views
akash.dinkar12 asked Jun 27, 2019
505 views
Show that when all elements are distinct, the best-case running time of HEAPSORT is $\Omega(n\lg\ n)$.
1 1 vote
2 2 answers
2.1k
2.1k views
lalitver10 asked Jan 13, 2022
2,136 views
Question The time required to find the 99th smallest element from a min heap of n elements is (given that we have access to the array elements)
2 2 votes
1 answers 1 answer
2.4k
2.4k views
shivani2010 asked Jun 15, 2016
2,398 views
The time complexity to build a heap with a list of n numbers isO(log n)O(n)O(n logn)O(n$^2$)
2 2 votes
1 1 answer
158
158 views
GO Classes asked Jul 21
158 views
A max-heap is stored using $0$-based indexing as:$$[60, 30, 45, 15, 5, 10, 20]$$During the first iteration of heap sort:Swap the root with the last element. Reduce the he...