Finding the median of an unsorted array

algorithmheapmedian

To find the median of an unsorted array, we can make a min-heap in O(nlogn) time for n elements, and then we can extract one by one n/2 elements to get the median. But this approach would take O(nlogn) time.

Can we do the same by some method in O(n) time? If we can, then please tell or suggest some method.

Best Answer

You can use the Median of Medians algorithm to find median of an unsorted array in linear time.