1 1 vote Q : What is the running time of heap sort for presorted input of size n? O(n) B) O(n^2) C) O(nlogn) D) O(logn) In the question they didn’t mention if its a max or min heap and also they didn’t mention if the “presorted” input is in ascending or descending order. For example, if we take max heap, if the order of input is decreasing order, the time complexity would be O(n) and for decresing order it would be O(nlogn). Is the question incomplete or am i missing some concepts? Algorithms ace-test-series heap-sort algorithms + – OneZero 1.9k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Hemanth_13 commented Dec 24, 2018 reply Follow flag Brother I'm unable find the question.. Could you please check 0 0 replyShare OneZero commented Dec 24, 2018 reply Follow flag sry i didnt insert the image :P 0 0 replyShare OneZero commented Dec 24, 2018 reply Follow flag @Hemanth_13 Fixed it 0 0 replyShare Hemanth_13 commented Dec 24, 2018 reply Follow flag I think though it is sorted we have to build heap and delete an element and reheapify ==> O(nlogn) What was the answer provided. 0 0 replyShare aambazinga commented Dec 24, 2018 reply Follow flag heap sort works impartially for all the worst, best as well as average case, and it is O(nlogn). it will always do these 3 steps-- 1) build (min/max) heap 2) for i=length(heap) down to 1 delete A[1] and A[i] decrement the size of heap by 1 min/max heapify. No Concession will be there for sorted array. 0 0 replyShare aimhigh commented Dec 24, 2018 reply Follow flag Is it nlogn? 0 0 replyShare OneZero commented Dec 24, 2018 reply Follow flag Yes its O(nlogn) sorry, i thought it was create heap. my bad 0 0 replyShare Please log in or register to add a comment.