How do I find the median of numbers in linear time using heaps?
问题 Wikipedia says: Selection algorithms: Finding the min, max, both the min and max, median , or even the k-th largest element can be done in linear time using heaps. All it says is that it can be done, and not how. Can you give me some start on how this can be done using heaps? 回答1: You would use a min-max-median heap to find the min, max and median in constant time (and take linear time to build the heap). You can use order-statistics trees to find the kth smallest/largest value. Both of these