edited by
1,095 views
0 votes
0 votes

gate heap sort question

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

edited by

2 Answers

0 votes
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 votes
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

Related questions

0 votes
0 votes
0 answers
1
akash.dinkar12 asked Jun 27, 2019
326 views
Show that when all elements are distinct, the best-case running time of HEAPSORT is $\Omega(n\lg\ n)$.
1 votes
1 votes
2 answers
2
lalitver10 asked Jan 13, 2022
1,071 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)
1 votes
1 votes
1 answer
4