Abstract
The Cartesian-tree pattern matching is a recently introduced scheme of pattern matching that detects fragments in a sequential data stream which have a similar structure as a query pattern. Formally, Cartesian-tree pattern matching seeks all substrings \(S'\) of the text string S such that the Cartesian tree of \(S'\) and that of a query pattern P coincide. In this paper, we present a new indexing structure for this problem, called the Cartesian-tree Position Heap (CPH). Let n be the length of the input text string S, m the length of a query pattern P, and \(\sigma \) the alphabet size. We show that the CPH of S, denoted \(\mathsf {CPH}(S)\), supports pattern matching queries in \(O(m (\sigma + \log (\min \{h, m\})) + occ )\) time with O(n) space, where h is the height of the CPH and \( occ \) is the number of pattern occurrences. We show how to build \(\mathsf {CPH}(S)\) in \(O(n \log \sigma )\) time with O(n) working space. Further, we extend the problem to the case where the text is a labeled tree (i.e. a trie). Given a trie \(\boldsymbol{T}\) with N nodes, we show that the CPH of \(\boldsymbol{T}\), denoted \(\mathsf {CPH}(\boldsymbol{T})\), supports pattern matching queries on the trie in \(O(m (\sigma ^2 + \log (\min \{h, m\})) + occ )\) time with \(O(N \sigma )\) space. We also show a construction algorithm for \(\mathsf {CPH}(\boldsymbol{T})\) running in \(O(N \sigma )\) time and \(O(N \sigma )\) working space.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
References
Alstrup, S., Holm, J.: Improved algorithms for finding level ancestors in dynamic trees. In: Montanari, U., Rolim, J.D.P., Welzl, E. (eds.) ICALP 2000. LNCS, vol. 1853, pp. 73–84. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-45022-X_8
Amir, A., Farach, M., Idury, R.M., Poutré, J.A.L., Schäffer, A.A.: Improved dynamic dictionary matching. Inf. Comput. 119(2), 258–282 (1995)
Baker, B.S.: A theory of parameterized pattern matching: algorithms and applications. In: STOC 1993, pp. 71–80 (1993)
Baker, B.S.: Parameterized pattern matching by Boyer-Moore type algorithms. In: Proceedings of 6th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 541–550 (1995)
Baker, B.S.: Parameterized pattern matching: algorithms and applications. J. Comput. Syst. Sci. 52(1), 28–42 (1996)
Bender, M.A., Farach-Colton, M.: The level ancestor problem simplified. Theor. Comput. Sci. 321(1), 5–12 (2004)
Cho, S., Na, J.C., Park, K., Sim, J.S.: A fast algorithm for order-preserving pattern matching. Inf. Process. Lett. 115(2), 397–402 (2015)
Coffman, E., Eve, J.: File structures using hashing functions. Commun. ACM 13, 427–432 (1970)
Crochemore, M., et al.: Order-preserving indexing. Theor. Comput. Sci. 638, 122–135 (2016)
Ehrenfeucht, A., McConnell, R.M., Osheim, N., Woo, S.W.: Position heaps: a simple and dynamic text indexing data structure. J. Discrete Algorithms 9(1), 100–121 (2011)
Fu, T., Chung, K.F., Luk, R.W.P., Ng, C.: Stock time series pattern matching: Template-based vs. rule-based approaches. Eng. Appl. Artif. Intell. 20(3), 347–364 (2007)
Fujisato, N., Nakashima, Y., Inenaga, S., Bannai, H., Takeda, M.: Right-to-left online construction of parameterized position heaps. In: PSC 2018, pp. 91–102 (2018)
Fujisato, N., Nakashima, Y., Inenaga, S., Bannai, H., Takeda, M.: The parameterized position heap of a trie. In: Heggernes, P. (ed.) CIAC 2019. LNCS, vol. 11485, pp. 237–248. Springer, Cham (2019). https://doi.org/10.1007/978-3-030-17402-6_20
I., T., Inenaga, S., Takeda, M.: Palindrome pattern matching. In: Giancarlo, R., Manzini, G. (eds.) CPM 2011. LNCS, vol. 6661, pp. 232–245. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-21458-5_21
Kim, H., Han, Y.: OMPPM: online multiple palindrome pattern matching. Bioinformatics 32(8), 1151–1157 (2016)
Kim, J., et al.: Order-preserving matching. Theor. Comput. Sci. 525, 68–79 (2014)
Matsuoka, Y., Aoki, T., Inenaga, S., Bannai, H., Takeda, M.: Generalized pattern matching and periodicity under substring consistent equivalence relations. Theor. Comput. Sci. 656, 225–233 (2016)
Park, S.G., Bataa, M., Amir, A., Landau, G.M., Park, K.: Finding patterns and periods in cartesian tree matching. Theor. Comput. Sci. 845, 181–197 (2020)
Song, S., Gu, G., Ryu, C., Faro, S., Lecroq, T., Park, K.: Fast algorithms for single and multiple pattern Cartesian tree matching. Theor. Comput. Sci. 849, 47–63 (2021)
Weiner, P.: Linear pattern-matching algorithms. In: Proceedings of 14th IEEE Annual Symposium on Switching and Automata Theory, pp. 1–11 (1973)
Westbrook, J.: Fast incremental planarity testing. In: Kuich, W. (ed.) ICALP 1992. LNCS, vol. 623, pp. 342–353. Springer, Heidelberg (1992). https://doi.org/10.1007/3-540-55719-9_86
Acknowledgments
This work was supported by JSPS KAKENHI Grant Numbers JP18K18002 (YN) and JP21K17705 (YN), and by JST PRESTO Grant Number JPMJPR1922 (SI).
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2021 Springer Nature Switzerland AG
About this paper
Cite this paper
Nishimoto, A., Fujisato, N., Nakashima, Y., Inenaga, S. (2021). Position Heaps for Cartesian-Tree Matching on Strings and Tries. In: Lecroq, T., Touzet, H. (eds) String Processing and Information Retrieval. SPIRE 2021. Lecture Notes in Computer Science(), vol 12944. Springer, Cham. https://doi.org/10.1007/978-3-030-86692-1_20
Download citation
DOI: https://doi.org/10.1007/978-3-030-86692-1_20
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-86691-4
Online ISBN: 978-3-030-86692-1
eBook Packages: Computer ScienceComputer Science (R0)