Towards Optimal Range Medians

  • Beat Gfeller
  • Peter Sanders
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5555)


We consider the following problem: given an unsorted array of n 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) time to answer k such median queries. This improves previous algorithms by a logarithmic factor and matches a lower bound for k = O(n). Since, in contrast to previous approaches, 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.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [BFC04]
    Bender, M.A., Farach-Colton, M.: The Level Ancestor Problem simplified. Theor. Comput. Sci. 321(1), 5–12 (2004)MathSciNetCrossRefMATHGoogle Scholar
  2. [BFP+72]
    Blum, M., Floyd, R.W., Pratt, V.R., Rivest, R.L., Tarjan, R.E.: Linear Time Bounds for Median Computations. In: 4th Annual Symp. on Theory of Computing (STOC), pp. 119–124 (1972)Google Scholar
  3. [CG86]
    Chazelle, B., Guibas, L.J.: Fractional cascading: I. A data structuring technique. Algorithmica 1, 133–162 (1986)MathSciNetCrossRefMATHGoogle Scholar
  4. [Cla88]
    Clark, D.R.: Compact Pat Trees. PhD thesis, University of Waterloo (1988)Google Scholar
  5. [CWE07]
    Cline, D., White, K.B., Egbert, P.K.: Fast 8-bit median filtering based on separability. In: IEEE International Conference on Image Processing (ICIP), vol. 5, pp. 281–284 (2007)Google Scholar
  6. [dBvKOS00]
    de Berg, M., van Kreveld, M., Overmars, M., Schwarzkopf, O.: Computational Geometry Algorithms and Applications, 2nd edn. Springer, Heidelberg (2000)MATHGoogle Scholar
  7. [GS09]
    Gfeller, B., Sanders, P.: Towards optimal range medians. CoRR, abs/0901.1761 (2009)Google Scholar
  8. [GW93]
    Gil, J., Werman, M.: Computing 2-d min, median, and max filters. IEEE Transactions on Pattern Analysis and Machine Intelligence 15(5), 504–507 (1993)CrossRefGoogle Scholar
  9. [HPM08]
    Har-Peled, S., Muthukrishnan, S.M.: Range Medians. In: Halperin, D., Mehlhorn, K. (eds.) Esa 2008. LNCS, vol. 5193, pp. 503–514. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  10. [JMS04]
    JáJá, J., Mortensen, C.W., Shi, Q.: Space-efficient and fast algorithms for multidimensional dominance reporting and counting. In: Fleischer, R., Trippen, G. (eds.) ISAAC 2004. LNCS, vol. 3341, pp. 558–568. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  11. [KMS05]
    Krizanc, D., Morin, P., Smid, M.H.M.: Range Mode and Range Median Queries on Lists and Trees. Nord. J. Comput. 12(1), 1–17 (2005)MathSciNetMATHGoogle Scholar
  12. [Meh84]
    Mehlhorn, K.: Data structures and algorithms. Sorting and Searching, vol. 1. Springer, Berlin (1984)MATHGoogle Scholar
  13. [NR72]
    Nievergelt, J., Reingold, E.M.: Binary Search Trees of Bounded Balance. In: 4th Annual Symp. on Theory of Computing (STOC), pp. 137–142. ACM Press, New York (1972)Google Scholar
  14. [OS06]
    Okanohara, D., Sadakane, K.: Practical entropy-compressed rank/select dictionary. The Computing Research Repository (CoRR), abs/cs/0610001 (2006)Google Scholar
  15. [Pet08]
    Petersen, H.: Improved Bounds for Range Mode and Range Median Queries. In: Geffert, V., Karhumäki, J., Bertoni, A., Preneel, B., Návrat, P., Bieliková, M. (eds.) SOFSEM 2008. LNCS, vol. 4910, pp. 418–423. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  16. [PG09]
    Petersen, H., Grabowski, S.: Range mode and range median queries in constant time and sub-quadratic space. Information Processing Letters 109(4), 225–228 (2009)MathSciNetCrossRefMATHGoogle Scholar
  17. [PH07]
    Perreault, S., Hébert, P.: Median filtering in constant time. IEEE Transactions on Image Processing 16(9), 2389–2394 (2007)MathSciNetCrossRefGoogle Scholar
  18. [Rou01]
    Roura, S.: A New Method for Balancing Binary Search Trees. In: Orejas, F., Spirakis, P.G., van Leeuwen, J. (eds.) ICALP 2001. LNCS, vol. 2076, pp. 469–480. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  19. [VSIR91]
    Varman, P.J., Scheufler, S.D., Iyer, B.R., Ricard, G.R.: Merging multiple lists on hierarchical-memory multiprocessors. J. Parallel Distrib. Comput. 12(2), 171–177 (1991)CrossRefMATHGoogle Scholar
  20. [WL85]
    Willard, D.E., Lueker, G.S.: Adding range restriction capability to dynamic data structures. J. ACM 32(3), 597–617 (1985)MathSciNetCrossRefMATHGoogle Scholar
  21. [Yao82]
    Yao, A.C.-C.: Space-time tradeoff for answering range queries (extended abstract). In: 14th Annual Symp. on Theory of Computing (STOC), pp. 128–136 (1982)Google Scholar
  22. [Yao85]
    Yao, A.C.-C.: On the Complexity of Maintaining Partial Sums. SIAM J. Comput. 14(2), 277–288 (1985)MathSciNetCrossRefMATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Beat Gfeller
    • 1
  • Peter Sanders
    • 2
  1. 1.ETH ZürichSwitzerland
  2. 2.Universität KarlsruheGermany

Personalised recommendations