Interview Question
Country: India
Interview Type: Written Test
We get nlogn to place n elements into their correct positions. So, in logn time, we place 1 element into its correct position.
using heap sort to get the fist k elements out of N elements, it takes O(N)+O(k log N) time. The question clearly states there are N elements, so to sort the first k elements out of the N elements it would take O(N)+O(k log N) time using heapsort.
So O(log N) time is not enough even to find the first element of the array in sorted order.
A single element can be placed to its final location in log(n) time.
- Expressions April 06, 2013