Abstract
We present \(O(n)\)-space data structures to support various range frequency queries on a given array \(A[0:n-1]\) or tree \(T\) with \(n\) nodes. Given a query consisting of an arbitrary pair of pre-order rank indices \((i,j)\), our data structures return a least frequent element, mode, \(\alpha \)-minority, or top-\(k\) colors (values) of the multiset of elements in the unique path with endpoints at indices \(i\) and \(j\) in \(A\) or \(T\). We describe a data structure that supports range least frequent element queries on arrays in \(O(\sqrt{n / w})\) time, improving the \({\varTheta }(\sqrt{n})\) worst-case time required by the data structure of Chan et al. (SWAT 2012), where \(w \in {\varOmega }(\log n)\) is the word size in bits. We describe a data structure that supports path mode queries on trees in \(O(\log \log n \sqrt{n / w})\) time, improving the \({\varTheta }(\sqrt{n} \log n)\) worst-case time required by the data structure of Krizanc et al. (ISAAC 2003). We describe the first data structures to support path least frequent element queries, path \(\alpha \)-minority queries, and path top-\(k\) color queries on trees in \(O(\log \log n \sqrt{n/w}),\,O(\alpha ^{-1} \log \log n)\), and \(O(k)\) time, respectively, where \(\alpha \in [0,1]\) and \(k \in \{1,\ldots , n\}\) are specified at query time.
Similar content being viewed by others
References
Belazzougui, D., Botelho, F.C., Dietzfelbinger, M.: Hash, displace, and compress. In: Proceedings of ESA, LNCS, vol. 5757, pp. 682–693. Springer (2009)
Belazzougui, D., Gagie, T., Navarro, G.: Better space bounds for parameterized range majority and minority. In: Proceedings of WADS, LNCS, vol. 8037. Springer (2013)
Belazzougui, D., Navarro, G.: New lower and upper bounds for representing sequences. In: Proceedings of ESA, LNCS, vol. 7501, pp. 181–192. Springer (2012)
Belazzougui, D., Navarro, G., Valenzuela, D.: Improved compressed indexes for full-text document retrieval. J. Discrete Algorithms 18, 3–13 (2013)
Bender, M.A., Farach-Colton, M.: The LCA problem revisited. In: Proceedings of LATIN, LNCS, vol. 1776, pp. 88–94. Springer (2000)
Bender, M.A., Farach-Colton, M., Pemmasani, G., Skiena, S., Sumazin, P.: Lowest common ancestors in trees and directed acyclic graphs. J. Algorithms 57(2), 75–94 (2005)
Brodal, G.S., Gfeller, B., Jørgensen, A.G., Sanders, P.: Towards optimal range medians. Theor. Comput. Sci. 412(24), 2588–2601 (2011)
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 STACS, vol. 14, pp. 291–301 (2012)
Chan, T.M., Durocher, S., Larsen, K.G., Morrison, J., Wilkinson, B.T.: Linear-space data structures for range mode query in arrays. Theor. Comput. Syst. 55(4), 719–741 (2014)
Chan, T.M., Durocher, S., Skala, M., Wilkinson, B.T.: Linear-space data structures for range minority query in arrays. In: Proceedings of SWAT, LNCS, vol. 7357, pp. 295–306. Springer (2012)
Chazelle, B.: Filtering search: a new approach to query-answering. SIAM J. Comput. 15(3), 703–724 (1986)
Davoodi, P., Raman, R., Rao, S.S.: Succinct representations of binary trees for range minimum queries. In: Proceedings of COCOON, LNCS, vol. 7434, pp. 396–407. Springer (2012)
Demaine, E.D., Landau, G.M., Weimann, O.: On cartesian trees and range minimum queries. In: Proceedings of ICALP, LNCS, vol. 5555, pp. 341–353. Springer (2009)
Durocher, S.: A simple linear-space data structure for constant-time range minimum query. In: Proceedings of Conference on Space Efficient Data Structures, Streams and Algorithms (Munro Festschrift), vol. 8066, pp. 48–60 (2013)
Durocher, S., He, M., Munro, J.I., Nicholson, P.K., Skala, M.: Range majority in constant time and linear space. In: Proceedings of ICALP, LNCS, vol. 6755, pp. 244–255. Springer (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)
Durocher, S., Munro, J.I., El-Zein, H., Thankachan, S.V.: Low space data structures for geometric range mode query. In: Proceedings of CCCG (2014)
Durocher, S., Shah, R., Skala, M., Thankachan, S.: Linear-space data structures for range frequency queries on arrays and trees. In: Proceedings of MFCS, LNCS, vol. 8087, pp. 325–336. Springer (2013)
Durocher, S., Shah, R., Skala, M., Thankachan, S.: Top-\(k\) color queries on tree paths. In: Proceedings of SPIRE, LNCS, vol. 8214, pp. 109–115. Springer (2013)
Emde Boas, P.V.: Preserving order in a forest in less than logarithmic time and linear space. Inf. Proc. Lett. 6(3), 80–82 (1977)
Fischer, J.: Optimal succinctness for range minimum queries. In: Proceedings of LATIN, LNCS, vol. 6034, pp. 158–169. Springer (2010)
Fredman, M.L., Willard, D.E.: Trans-dichotomous algorithms for minimum spanning trees and shortest paths. J. Comput. Syst. Sci. 48(3), 533–551 (1994)
Gagie, T., He, M., Munro, J.I., Nicholson, P.: Finding frequent elements in compressed 2D arrays and strings. In: Proceedings of SPIRE, LNCS, vol. 7024, pp. 295–300. Springer (2011)
Gagie, T., Kärkkäinen, J., Navarro, G., Puglisi, S.J.: Colored range queries and document retrieval. Theor. Comput. Sci. 483, 36–50 (2013)
Gagie, T., Puglisi, S.J., Turpin, A.: Range quantile queries: another virtue of wavelet trees. In: Proceedings of SPIRE, LNCS, vol. 5721, pp. 1–6. Springer (2009)
Gfeller, B., Sanders, P.: Towards optimal range medians. In: Proceedings of ICALP, LNCS, vol. 5555, pp. 475–486. Springer (2009)
Hagerup, T., Tholey, T.: Efficient minimal perfect hashing in nearly minimal space. In: Proceedings of STACS, LNCS, vol. 2010, pp. 317–326. Springer (2001)
He, M., Munro, J.I., Zhou, G.: Path queries in weighted trees. In: Proceedings of ISAAC, pp. 140–149 (2011)
He, M., Munro, J.I., Zhou, G.: Succinct data structures for path queries. In: Proceedings of ESA, pp. 575–586 (2012)
Hon, W.K., Shah, R., Vitter, J.S.: Space-efficient framework for top-k string retrieval problems. In: Proceedings of FOCS, pp. 713–722 (2009)
Jørgensen, A.G., Larsen, K.D.: Range selection and median: tight cell probe lower bounds and adaptive data structures. In: Proceedings of SODA, pp. 805–813 (2011)
Karpinski, M., Nekrich, Y.: Top-k color queries for document retrieval. In: Proceedings of SODA, pp. 401–411 (2011)
Krizanc, D., Morin, P., Smid, M.: Range mode and range median queries on lists and trees. In: Proceedings of ISAAC, LNCS, vol. 2906, pp. 517–526. Springer (2003)
Krizanc, D., Morin, P., Smid, M.: Range mode and range median queries on lists and trees. Nordic J. Comput. 12, 1–17 (2005)
Muthukrishnan, S.: Efficient algorithms for document retrieval problems. In: Proceedings of SODA, pp. 657–666 (2002)
Navarro, G., Nekrich, Y.: Top-\(k\) document retrieval in optimal time and linear space. In: Proceedings of SODA, pp. 1066–1077 (2012)
Patil, M., Shah, R., Thankachan, S.V.: Succinct representations of weighted trees supporting path queries. J. Discrete Algorithms 17, 103–108 (2012)
Sadakane, K., Navarro, G.: Fully-functional succinct trees. In: Proceedings of SODA, pp. 134–149 (2010)
Schmidt, J.P., Siegel, A.: The spatial complexity of oblivious k-probe hash functions. SIAM J. Comput. 19(5), 775–786 (1990)
Skala, M.: Array range queries. In: Proceedings of Conference on Space Efficient Data Structures, Streams and Algorithms (Munro Festschrift), vol. 8066, pp. 333–350 (2013)
Sleator, D.D., Tarjan, R.E.: A data structure for dynamic trees. J. Comput. Syst. Sci. 26(3), 362–391 (1983)
Acknowledgments
The authors thank the anonymous reviewers as well as Djamal Belazzougui for their helpful suggestions. Part of this work was done while the fourth author was visiting the University of Manitoba in July 2012 and February 2013.
Author information
Authors and Affiliations
Corresponding author
Additional information
Work supported in part by the Natural Sciences and Engineering Research Council of Canada (NSERC) and National Science Foundation (NSF) Grants CCF–1017623 (R. Shah) and CCF–1218904 (R. Shah). Preliminary versions of some of these results appeared at the International Symposium on Mathematical Foundations of Computer Science (MFCS) [18] and the String Processing and Information Retrieval Symposium (SPIRE) [19].
Rights and permissions
About this article
Cite this article
Durocher, S., Shah, R., Skala, M. et al. Linear-Space Data Structures for Range Frequency Queries on Arrays and Trees. Algorithmica 74, 344–366 (2016). https://doi.org/10.1007/s00453-014-9947-8
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00453-014-9947-8