You would use the min-max-median heap to find min, max and median in constant time (and take linear time to create the heap). You can use order statistics trees to find the kth smallest / largest value. Both of these data structures are described in this article on the min-max heap [pdf link] . Min-max heaps are binary heaps that alternate between minimum heaps and maximum heaps.
From the article: Min-max-median heap is a binary heap with the following properties:
1) The median of all elements is at the root
2) The left subtree of the root is a bunch of min-max Hl-sized ceilings [((n-1) / 2)] containing elements that are less than or equal to the median. The right subtree is a heap of max-min Hr of size floor [((n-1) / 2)] containing only elements greater than or equal to the median.
The rest of the article explains how to build such a bunch.
Editing. When reading paper in more detail, it seems that building min-max-median heaps requires that you first find the median (FTA: "Find the median of all n elements using any known linear time algorithm"). However, once you have built the heap, you can maintain the median simply by maintaining a balance between the min-max heap on the left and the max-min heap on the right. DeleteMedian replaces the root with either the minimum heap max-min or the max heap min-max (depending on which balance is retained).
So, if you plan to use the min-max-median heap to find the median of a fixed dataset, then you are SOL, but if you use it in a changing dataset, it is possible.
Niki Yoshiuchi Apr 09 '10 at 23:34 on 2010-04-09 23:34
source share