Advertisement

Theory of Computing Systems

, Volume 55, Issue 4, pp 719–741 | Cite as

Linear-Space Data Structures for Range Mode Query in Arrays

  • Timothy M. Chan
  • Stephane Durocher
  • Kasper Green Larsen
  • Jason Morrison
  • Bryan T. Wilkinson
Article

Abstract

A mode of a multiset S is an element aS of maximum multiplicity; that is, a occurs at least as frequently as any other element in S. Given an array A[1:n] of n elements, we consider a basic problem: constructing a static data structure that efficiently answers range mode queries on A. Each query consists of an input pair of indices (i,j) for which a mode of A[i:j] must be returned. The best previous data structure with linear space, by Krizanc, Morin, and Smid (Proceedings of the International Symposium on Algorithms and Computation (ISAAC), pp. 517–526, 2003), requires \(\varTheta (\sqrt{n}\log\log n)\) query time in the worst case. We improve their result and present an O(n)-space data structure that supports range mode queries in \(O(\sqrt{n/\log n})\) worst-case time. In the external memory model, we give a linear-space data structure that requires \(O(\sqrt{n/B})\) I/Os per query, where B denotes the block size. Furthermore, we present strong evidence that a query time significantly below \(\sqrt{n}\) cannot be achieved by purely combinatorial techniques; we show that boolean matrix multiplication of two \(\sqrt{n} \times \sqrt{n}\) matrices reduces to n range mode queries in an array of size O(n).

Additionally, we give linear-space data structures for the dynamic problem (queries and updates in near O(n 3/4) time), for orthogonal range mode in d dimensions (queries in near O(n 1−1/2d ) time) and for half-space range mode in d dimensions (queries in \(O(n^{1-1/d^{2}})\) time). Finally, we complement our dynamic data structure with a reduction from the multiphase problem, again supporting that we cannot hope for much more efficient data structures.

Keywords

Mode Range query Data structure Linear space Array 

Notes

Acknowledgements

The authors thank Peyman Afshani, Francisco Claude, Meng He, Ian Munro, Patrick Nicholson, Matthew Skala, and Norbert Zeh for discussing various topics related to range searching.

References

  1. 1.
    Agarwal, P.K.: Range searching. In: Goodman, J., O’Rourke, J. (eds.) Handbook of Discrete and Computational Geometry, 2nd edn., pp. 809–837. CRC Press, New York (2004) Google Scholar
  2. 2.
    Alon, N., Schieber, B.: Optimal preprocessing for answering on-line product queries. Technical report 71/87, Tel-Aviv University (1987) Google Scholar
  3. 3.
    Amir, A., Fischer, J., Lewenstein, M.: Two-dimensional range minimum queries. In: Proceedings of the Symposium on Combinatorial Pattern Matching (CPM). Lecture Notes in Computer Science, vol. 4580, pp. 286–294. Springer, Berlin (2007) CrossRefGoogle Scholar
  4. 4.
    Bansal, N., Williams, R.: Regularity lemmas and combinatorial algorithms. In: Proceedings of the IEEE Symposium on Foundations of Computer Science (FOCS), pp. 745–754 (2009) Google Scholar
  5. 5.
    Bender, M.A., Farach-Colton, M.: The LCA problem revisited. In: Proceedings of the Latin American Theoretical Informatics Symposium (LATIN). Lecture Notes in Computer Science, vol. 1776, pp. 88–94. Springer, Berlin (2000) Google Scholar
  6. 6.
    Berkman, O., Breslauer, D., Galil, Z., Schieber, B., Vishkin, U.: Highly parallelizable problems. In: Proceedings of the ACM Symposium on the Theory of Computing (STOC), pp. 309–319 (1989) Google Scholar
  7. 7.
    Bose, P., Kranakis, E., Morin, P., Tang, Y.: Approximate range mode and range median queries. In: Proceedings of the International Symposium on Theoretical Aspects of Computer Science (STACS). Lecture Notes in Computer Science, vol. 3404, pp. 377–388. Springer, Berlin (2005) Google Scholar
  8. 8.
    Brodal, G.S., Jørgensen, A.G.: Data structures for range median queries. In: Proceedings of the International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 5878, pp. 822–831. Springer, Berlin (2009) Google Scholar
  9. 9.
    Brodal, G.S., Davoodi, P., Rao, S.S.: On space efficient two dimensional range minimum data structures. In: Proceedings of the European Symposium on Algorithms (ESA). Lecture Notes in Computer Science., vol. 6346/6347. Springer, Berlin (2010) Google Scholar
  10. 10.
    Brodal, G.S., Davoodi, P., Rao, S.S.: Path minima queries in dynamic weighted trees. In: Proceedings of the Workshop on Algorithms and Data Structures (WADS). Lecture Notes in Computer Science, vol. 6844, pp. 290–301. Springer, Berlin (2011) CrossRefGoogle Scholar
  11. 11.
    Brodal, G.S., Gfeller, B., Jørgensen, A.G., Sanders, P.: Towards optimal range medians. Theor. Comput. Sci. 412(24), 2588–2601 (2011) CrossRefzbMATHGoogle Scholar
  12. 12.
    Brodal, G.S., Davoodi, P., Lewenstein, M., Raman, R., Rao, S.S.: Two dimensional range minimum queries and Fibonacci lattices. In: Proceedings of the European Symposium on Algorithms (ESA). Lecture Notes in Computer Science, vol. 7501, pp. 217–228. Springer, Berlin (2012) Google Scholar
  13. 13.
    Chan, T.M.: Optimal partition trees. Discrete Comput. Geom. 47(4), 661–690 (2012) MathSciNetCrossRefzbMATHGoogle Scholar
  14. 14.
    Chan, T.M., Pătraşcu, M.: Counting inversions, offline orthogonal range counting, and related problems. In: Proceedings of the ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 161–173 (2010) CrossRefGoogle Scholar
  15. 15.
    Chan, T.M., Durocher, S., Larsen, K.G., Morrison, J., Wilkinson, B.T.: Linear-space data structures for range mode query in arrays. In: Proceedings of the International Symposium on Theoretical Aspects of Computer Science (STACS). Leibniz International Proceedings in Informatics, vol. 14, pp. 291–301 (2012) Google Scholar
  16. 16.
    Chan, T.M., Durocher, S., Skala, M., Wilkinson, B.T.: Linear-space data structures for range minority query in arrays. In: Proceedings of the Scandinavian Symposium and Workshops on Algorithm Theory (SWAT). Lecture Notes in Computer Science, vol. 7357, pp. 295–306. Springer, Berlin (2012) Google Scholar
  17. 17.
    Chazelle, B.: Cutting hyperplanes for divide-and-conquer. Discrete Comput. Geom. 9(2), 145–158 (1993) MathSciNetCrossRefzbMATHGoogle Scholar
  18. 18.
    Chazelle, B.: Cuttings. In: Handbook of Data Structures and Applications, pp. 25.1–25.10. CRC Press, Boca Raton (2005) Google Scholar
  19. 19.
    Chazelle, B., Rosenberg, B.: Computing partial sums in multidimensional arrays. In: Proceedings of the ACM Symposium on Computational Geometry (SoCG), pp. 131–139 (1989) Google Scholar
  20. 20.
    Davoodi, P.: Data structures: range queries and space efficiency. Ph.D. thesis, Aarhus University (2011) Google Scholar
  21. 21.
    Davoodi, P., Raman, R., Satti, S.R.: Succinct representations of binary trees for range minimum queries. In: Proceedings of the International Computing and Combinatorics Conference (COCOON). Lecture Notes in Computer Science, vol. 7434, pp. 396–407. Springer, Berlin (2012) Google Scholar
  22. 22.
    de Berg, M., Cheong, O., van Kreveld, M., Overmars, M.: Computational Geometry: Algorithms and Applications, 3rd edn. Springer, Berlin (2008) CrossRefGoogle Scholar
  23. 23.
    Demaine, E.D., Landau, G.M., Weimann, O.: On Cartesian trees and range minimum queries. In: Proceedings of the International Colloquium on Automata, Languages, and Programming (ICALP). Lecture Notes in Computer Science, vol. 5555, pp. 341–353. Springer, Berlin (2009) CrossRefGoogle Scholar
  24. 24.
    Dietz, P.F.: Optimal algorithms for list indexing and subset rank. In: Proceedings of the Workshop on Algorithms and Data Structures (WADS). Lecture Notes in Computer Science, vol. 382, pp. 39–46. Springer, Berlin (1989) CrossRefGoogle Scholar
  25. 25.
    Dobkin, D., Munro, J.I.: Determining the mode. Theor. Comput. Sci. 12(3), 255–263 (1980) MathSciNetCrossRefzbMATHGoogle Scholar
  26. 26.
    Durocher, S.: A simple linear-space data structure for constant-time range minimum query. CoRR (2011). arXiv:1109.4460
  27. 27.
    Durocher, S., He, M., Munro, J.I., Nicholson, P.K., Skala, M.: Range majority in constant time and linear space. In: Proceedings of the International Colloquium on Automata, Languages, and Programming (ICALP). Lecture Notes in Computer Science, vol. 6755, pp. 244–255. Springer, Berlin (2011) CrossRefGoogle Scholar
  28. 28.
    Durocher, S., He, M., Munro, J.I., Nicholson, P.K., Skala, M.: Range majority in constant time and linear space. Inf. Comput. 222, 169–179 (2013) MathSciNetCrossRefzbMATHGoogle Scholar
  29. 29.
    Elmasry, A., He, M., Munro, J.I., Nicholson, P.: Dynamic range majority data structures. In: Proceedings of the International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 7074, pp. 150–159. Springer, Berlin (2011) Google Scholar
  30. 30.
    Fischer, J.: Optimal succinctness for range minimum queries. In: Proceedings of the Latin American Theoretical Informatics Symposium (LATIN). Lecture Notes in Computer Science, vol. 6034, pp. 158–169. Springer, Berlin (2010) Google Scholar
  31. 31.
    Fischer, J., Heun, V.: Theoretical and practical improvements on the RMQ-problem, with applications to LCA and LCE. In: Proceedings of the Symposium on Combinatorial Pattern Matching (CPM). Lecture Notes in Computer Science, vol. 4009, pp. 36–48. Springer, Berlin (2006) CrossRefGoogle Scholar
  32. 32.
    Fischer, J., Heun, V.: A new succinct representation of RMQ-information and improvements in the enhanced suffix array. In: Proceedings of the International Symposium on Combinatorics, Algorithms, Probabilistic and Experimental Methodologies (ESCAPE). Lecture Notes in Computer Science, vol. 4614, pp. 459–470. Springer, Berlin (2007) CrossRefGoogle Scholar
  33. 33.
    Fischer, J., Heun, V.: Finding range minima in the middle: approximations and applications. Math. Comput. Sci. 3(1), 17–30 (2010) MathSciNetCrossRefzbMATHGoogle Scholar
  34. 34.
    Gabow, H.N., Bentley, J.L., Tarjan, R.E.: Scaling and related techniques for geometry problems. In: Proceedings of the ACM Symposium on the Theory of Computing (STOC), pp. 135–143 (1984) Google Scholar
  35. 35.
    Gagie, T., Puglisi, S.J., Turpin, A.: Range quantile queries: another virtue of wavelet trees. In: Proceedings of the String Processing and Information Retrieval Symposium (SPIRE). Lecture Notes in Computer Science, vol. 5721, pp. 1–6. Springer, Berlin (2009) CrossRefGoogle Scholar
  36. 36.
    Gagie, T., He, M., Munro, J.I., Nicholson, P.: Finding frequent elements in compressed 2D arrays and strings. In: Proceedings of the Symposium on String Processing and Information Retrieval (SPIRE). Lecture Notes in Computer Science, vol. 7024, pp. 295–300. Springer, Berlin (2011) CrossRefGoogle Scholar
  37. 37.
    Gfeller, B., Sanders, P.: Towards optimal range medians. In: Proceedings of the International Colloquium on Automata, Languages, and Programming (ICALP). Lecture Notes in Computer Science, vol. 5555, pp. 475–486. Springer, Berlin (2009) CrossRefGoogle Scholar
  38. 38.
    Golin, M.J., Iacono, J., Krizanc, D., Raman, R., Rao, S.S.: Encoding 2D range maximum queries. In: Proceedings of the International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 7074, pp. 180–189. Springer, Berlin (2011) Google Scholar
  39. 39.
    Greve, M., Jørgensen, A.G., Larsen, K.D., Truelsen, J.: Cell probe lower bounds and approximations for range mode. In: Proceedings of the International Colloquium on Automata, Languages, and Programming (ICALP). Lecture Notes in Computer Science, vol. 6198, pp. 605–616. Springer, Berlin (2010) CrossRefGoogle Scholar
  40. 40.
    Har-Peled, S., Muthukrishnan, S.: Range medians. In: Proceedings of the European Symposium on Algorithms (ESA). Lecture Notes in Computer Science, vol. 5193, pp. 503–514. Springer, Berlin (2008) Google Scholar
  41. 41.
    He, M., Munro, J.I., Nicholson, P.: Dynamic range selection in linear space. In: Proceedings of the International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 7074, pp. 160–169. Springer, Berlin (2011) Google Scholar
  42. 42.
    JáJá, J., Mortensen, C.W., Shi, Q.: Space-efficient and fast algorithms for multidimensional dominance reporting and counting. In: Proceedings of the International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 3341, pp. 558–568. Springer, Berlin (2004) Google Scholar
  43. 43.
    Jørgensen, A.G.: Data structures: sequence problems, range queries, and fault tolerance. Ph.D. thesis, Aarhus University (2010) Google Scholar
  44. 44.
    Jørgensen, A.G., Larsen, K.D.: Range selection and median: tight cell probe lower bounds and adaptive data structures. In: Proceedings of the ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 805–813 (2011) CrossRefGoogle Scholar
  45. 45.
    Krizanc, D., Morin, P., Smid, M.: Range mode and range median queries on lists and trees. In: Proceedings of the International Symposium on Algorithms and Computation (ISAAC). Lecture Notes in Computer Science, vol. 2906, pp. 517–526. Springer, Berlin (2003) Google Scholar
  46. 46.
    Krizanc, D., Morin, P., Smid, M.: Range mode and range median queries on lists and trees. Nord. J. Comput. 12, 1–17 (2005) MathSciNetzbMATHGoogle Scholar
  47. 47.
    Larsen, K.G.: The cell probe complexity of dynamic range counting. In: Proceedings of the ACM Symposium on the Theory of Computing (STOC), pp. 85–94 (2012) Google Scholar
  48. 48.
    Matoušek, J.: Range searching with efficient hierarchical cuttings. Discrete Comput. Geom. 10(2), 157–182 (1993) MathSciNetCrossRefzbMATHGoogle Scholar
  49. 49.
    Munro, J.I.: Tables. In: Chandru, V., Vinay, V. (eds.) Foundations of Software Technology and Theoretical Computer Science. Lecture Notes in Computer Science, vol. 1180, pp. 37–42. Springer, Berlin (1996) CrossRefGoogle Scholar
  50. 50.
    Munro, J.I., Spira, M.: Sorting and searching in multisets. SIAM J. Comput. 5(1), 1–8 (1976) MathSciNetCrossRefzbMATHGoogle Scholar
  51. 51.
    Nekrich, Y.: Orthogonal range searching in linear and almost-linear space. In: Proceedings of the Workshop on Algorithms and Data Structures (WADS). Lecture Notes in Computer Science, vol. 4619, pp. 15–26. Springer, Berlin (2007) CrossRefGoogle Scholar
  52. 52.
    Pǎtraşcu, M.: Towards polynomial lower bounds for dynamic problems. In: Proceedings of the ACM Symposium on the Theory of Computing (STOC), pp. 603–610 (2010) Google Scholar
  53. 53.
    Petersen, H.: Improved bounds for range mode and range median queries. In: Proceedings of the Conference on Current Trends in Theory and Practice of Computer Science (SOFSEM). Lecture Notes in Computer Science, vol. 4910, pp. 418–423. Springer, Berlin (2008) Google Scholar
  54. 54.
    Petersen, H., Grabowski, S.: Range mode and range median queries in constant time and sub-quadratic space. Inf. Process. Lett. 109, 225–228 (2009) MathSciNetCrossRefzbMATHGoogle Scholar
  55. 55.
    Poon, C.K.: Optimal range max datacub for fixed dimensions. In: Proceedings of the International Conference on Database Theory (ICDT). Lecture Notes in Computer Science, vol. 2572, pp. 158–172. Springer, Berlin (2003) Google Scholar
  56. 56.
    Sadakane, K.: Succinct data structures for flexible text retrieval systems. J. Discrete Algorithms 5, 12–22 (2007) MathSciNetCrossRefzbMATHGoogle Scholar
  57. 57.
    Skiena, S.: The Algorithm Design Manual, 2nd edn. Springer, Berlin (2008) CrossRefzbMATHGoogle Scholar
  58. 58.
    van Emde Boas, P.: Preserving order in a forest in less than logarithmic time and linear space. Inf. Process. Lett. 6(3), 80–82 (1977) CrossRefzbMATHGoogle Scholar
  59. 59.
    Vassilevska Williams, V.: Multiplying matrices faster than Coppersmith-Winograd. In: Proceedings of the ACM Symposium on the Theory of Computing (STOC), pp. 887–898 (2012) Google Scholar
  60. 60.
    Yao, A.C.: Space-time tradeoff for answering range queries. In: Proceedings of the ACM Symposium on the Theory of Computing (STOC), pp. 128–136 (1982) Google Scholar
  61. 61.
    Yao, A.C.: On the complexity of maintaining partial sums. SIAM J. Comput. 14, 277–288 (1985) MathSciNetCrossRefzbMATHGoogle Scholar
  62. 62.
    Yuan, H., Atallah, M.J.: Data structures for range minimum queries. In: Proceedings of the ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 150–160 (2010) CrossRefGoogle Scholar

Copyright information

© Springer Science+Business Media New York 2013

Authors and Affiliations

  • Timothy M. Chan
    • 1
  • Stephane Durocher
    • 2
  • Kasper Green Larsen
    • 3
  • Jason Morrison
    • 2
  • Bryan T. Wilkinson
    • 3
  1. 1.University of WaterlooWaterlooCanada
  2. 2.University of ManitobaWinnipegCanada
  3. 3.Aarhus UniversityAarhusDenmark

Personalised recommendations