Abstract
A mode of a multiset S is an element a∈S 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.
Similar content being viewed by others
Notes
Although the time required to complete a linear scan could be reduced by instead using a binary search or a more efficient predecessor data structure, the asymptotic worst-case time remains unchanged; for simplicity, a linear scan suffices.
Succinct data structures can ensure that space usage is very close to the length of the bit string up to lower-order terms, but this fact is not needed in our application.
References
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)
Alon, N., Schieber, B.: Optimal preprocessing for answering on-line product queries. Technical report 71/87, Tel-Aviv University (1987)
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)
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)
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)
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)
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)
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)
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)
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)
Brodal, G.S., Gfeller, B., Jørgensen, A.G., Sanders, P.: Towards optimal range medians. Theor. Comput. Sci. 412(24), 2588–2601 (2011)
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)
Chan, T.M.: Optimal partition trees. Discrete Comput. Geom. 47(4), 661–690 (2012)
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)
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)
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)
Chazelle, B.: Cutting hyperplanes for divide-and-conquer. Discrete Comput. Geom. 9(2), 145–158 (1993)
Chazelle, B.: Cuttings. In: Handbook of Data Structures and Applications, pp. 25.1–25.10. CRC Press, Boca Raton (2005)
Chazelle, B., Rosenberg, B.: Computing partial sums in multidimensional arrays. In: Proceedings of the ACM Symposium on Computational Geometry (SoCG), pp. 131–139 (1989)
Davoodi, P.: Data structures: range queries and space efficiency. Ph.D. thesis, Aarhus University (2011)
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)
de Berg, M., Cheong, O., van Kreveld, M., Overmars, M.: Computational Geometry: Algorithms and Applications, 3rd edn. Springer, Berlin (2008)
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)
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)
Dobkin, D., Munro, J.I.: Determining the mode. Theor. Comput. Sci. 12(3), 255–263 (1980)
Durocher, S.: A simple linear-space data structure for constant-time range minimum query. CoRR (2011). arXiv:1109.4460
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)
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)
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)
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)
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)
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)
Fischer, J., Heun, V.: Finding range minima in the middle: approximations and applications. Math. Comput. Sci. 3(1), 17–30 (2010)
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)
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)
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)
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)
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)
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)
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)
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)
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)
Jørgensen, A.G.: Data structures: sequence problems, range queries, and fault tolerance. Ph.D. thesis, Aarhus University (2010)
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)
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)
Krizanc, D., Morin, P., Smid, M.: Range mode and range median queries on lists and trees. Nord. J. Comput. 12, 1–17 (2005)
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)
Matoušek, J.: Range searching with efficient hierarchical cuttings. Discrete Comput. Geom. 10(2), 157–182 (1993)
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)
Munro, J.I., Spira, M.: Sorting and searching in multisets. SIAM J. Comput. 5(1), 1–8 (1976)
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)
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)
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)
Petersen, H., Grabowski, S.: Range mode and range median queries in constant time and sub-quadratic space. Inf. Process. Lett. 109, 225–228 (2009)
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)
Sadakane, K.: Succinct data structures for flexible text retrieval systems. J. Discrete Algorithms 5, 12–22 (2007)
Skiena, S.: The Algorithm Design Manual, 2nd edn. Springer, Berlin (2008)
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)
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)
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)
Yao, A.C.: On the complexity of maintaining partial sums. SIAM J. Comput. 14, 277–288 (1985)
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)
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.
Author information
Authors and Affiliations
Corresponding author
Additional information
A preliminary version of these results appeared at the 29th Symposium on Theoretical Aspects of Computer Science (STACS) [15]. Work was supported in part by the Natural Sciences and Engineering Research Council of Canada (NSERC), and in part by MADALGO—Center for Massive Data Algorithmics, a Center of the Danish National Research Foundation.
Rights and permissions
About this article
Cite this article
Chan, T.M., Durocher, S., Larsen, K.G. et al. Linear-Space Data Structures for Range Mode Query in Arrays. Theory Comput Syst 55, 719–741 (2014). https://doi.org/10.1007/s00224-013-9455-2
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00224-013-9455-2