in Algorithms retagged by
632 views
1 vote
1 vote

How much extra space is used by heapsort ?

  1. $O (1)$
  2. $O (\log n)$
  3. $O (n)$
  4. $O (n^2)$
in Algorithms retagged by
632 views

1 Answer

1 vote
1 vote
Best answer
Answer should be option A because heapsort in an inplace sorting technique and it doesn't require any extra space it uses the same array for sorting purpose
selected by

2 Comments

Can you do heapsort without recursion?
0
0

Yes sir it's possible

Max heap:

while ( i < = heapsize) {
 le <- left(i)
 ri <- right(i)
 if (le<=heapsize) and (A[le]>A[i])
  largest <- le
 else
  largest <- i 
 if (ri<=heapsize) and (A[ri]>A[largest])
  largest <- ri
 if (largest != i)
 {
   exchange A[i] <-> A[largest]
   i <- largest
 } 
 else
  break
}             
1
1
Answer: