Skip to main content

Position Heaps for Cartesian-Tree Matching on Strings and Tries

  • Conference paper
  • First Online:
String Processing and Information Retrieval (SPIRE 2021)

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

References

  1. 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

    Chapter  Google Scholar 

  2. 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)

    Article  MathSciNet  Google Scholar 

  3. Baker, B.S.: A theory of parameterized pattern matching: algorithms and applications. In: STOC 1993, pp. 71–80 (1993)

    Google Scholar 

  4. 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)

    Google Scholar 

  5. Baker, B.S.: Parameterized pattern matching: algorithms and applications. J. Comput. Syst. Sci. 52(1), 28–42 (1996)

    Article  MathSciNet  Google Scholar 

  6. Bender, M.A., Farach-Colton, M.: The level ancestor problem simplified. Theor. Comput. Sci. 321(1), 5–12 (2004)

    Article  MathSciNet  Google Scholar 

  7. 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)

    Article  MathSciNet  Google Scholar 

  8. Coffman, E., Eve, J.: File structures using hashing functions. Commun. ACM 13, 427–432 (1970)

    Article  Google Scholar 

  9. Crochemore, M., et al.: Order-preserving indexing. Theor. Comput. Sci. 638, 122–135 (2016)

    Article  MathSciNet  Google Scholar 

  10. 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)

    Article  MathSciNet  Google Scholar 

  11. 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)

    Article  Google Scholar 

  12. 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)

    Google Scholar 

  13. 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

    Chapter  Google Scholar 

  14. 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

    Chapter  MATH  Google Scholar 

  15. Kim, H., Han, Y.: OMPPM: online multiple palindrome pattern matching. Bioinformatics 32(8), 1151–1157 (2016)

    Article  Google Scholar 

  16. Kim, J., et al.: Order-preserving matching. Theor. Comput. Sci. 525, 68–79 (2014)

    Article  MathSciNet  Google Scholar 

  17. 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)

    Article  MathSciNet  Google Scholar 

  18. 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)

    Article  MathSciNet  Google Scholar 

  19. 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)

    Article  MathSciNet  Google Scholar 

  20. Weiner, P.: Linear pattern-matching algorithms. In: Proceedings of 14th IEEE Annual Symposium on Switching and Automata Theory, pp. 1–11 (1973)

    Google Scholar 

  21. 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

    Chapter  Google Scholar 

Download references

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

Authors

Corresponding author

Correspondence to Akio Nishimoto .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2021 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics