edited by
713 views
0 votes
0 votes
Why is space complexity of heap sort is O(1)? Everytime it calls Heapify() function at the root node of the heap and heapify in the worst case takes O(log n) space. Then why everywhere its written that heapsort is inplace sorting algorithm??

Another doubt is that what should be amswered in space complexity of an algorithm? The auxiliary space or the total space which include the input size as well??
edited by

1 Answer

0 votes
0 votes

The complexity of heap sort is not order of 1. it's nlogn. Second an in-place algorithm is an algorithm which transforms input using no auxiliary data structure. Means no extra space is taken. Heap sort is inplace as we can manipulate the input array itself to get the result. Third an algorithm is always free from the input variables. Means a algorithm time and space complexity does not depend on the style of input you give. So you never have to take in consideration the space used in input. 

Related questions

0 votes
0 votes
0 answers
1
1 votes
1 votes
3 answers
2
Shubhanshu asked Jun 6, 2017
1,636 views
You are asked to sort 15 randomly generated numbers. One should prefer—(a) Bubble sort (b) Quick sort (c) Merge sort (d) Heap sortI think the answer should be c or d cr...
0 votes
0 votes
1 answer
3
Ramayya asked Jan 7
192 views
Worst case time complexity of heap sort for n elementsO(nlogn)O(logn)O^2O(n)