English

Towards Optimal Range Medians

Data Structures and Algorithms 2009-01-14 v1

Abstract

We consider the following problem: given an unsorted array of nn elements, and a sequence of intervals in the array, compute the median in each of the subarrays defined by the intervals. We describe a simple algorithm which uses O(n) space and needs O(nlogk+klogn)O(n\log k + k\log n) time to answer the first kk queries. This improves previous algorithms by a logarithmic factor and matches a lower bound for k=O(n)k=O(n). Since the algorithm decomposes the range of element values rather than the array, it has natural generalizations to higher dimensional problems -- it reduces a range median query to a logarithmic number of range counting queries.

Keywords

Cite

@article{arxiv.0901.1761,
  title  = {Towards Optimal Range Medians},
  author = {Beat Gfeller and Peter Sanders},
  journal= {arXiv preprint arXiv:0901.1761},
  year   = {2009}
}
R2 v1 2026-06-21T12:00:11.630Z