English

Position Heaps for Cartesian-tree Matching on Strings and Tries

Data Structures and Algorithms 2021-08-17 v2

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 SS' of the text string SS such that the Cartesian tree of SS' and that of a query pattern PP coincide. In this paper, we present a new indexing structure for this problem called the Cartesian-tree Position Heap (CPH). Let nn be the length of the input text string SS, mm the length of a query pattern PP, and σ\sigma the alphabet size. We show that the CPH of SS, denoted CPH(S)\mathsf{CPH}(S), supports pattern matching queries in O(m(σ+log(min{h,m}))+occ)O(m (\sigma + \log (\min\{h, m\})) + occ) time with O(n)O(n) space, where hh is the height of the CPH and occocc is the number of pattern occurrences. We show how to build CPH(S)\mathsf{CPH}(S) in O(nlogσ)O(n \log \sigma) time with O(n)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 TT with NN nodes, we show that the CPH of TT, denoted CPH(T)\mathsf{CPH}(T), supports pattern matching queries on the trie in O(m(σ2+log(min{h,m}))+occ)O(m (\sigma^2 + \log (\min\{h, m\})) + occ) time with O(Nσ)O(N \sigma) space. We also show a construction algorithm for CPH(T)\mathsf{CPH}(T) running in O(Nσ)O(N \sigma) time and O(Nσ)O(N \sigma) working space.

Keywords

Cite

@article{arxiv.2106.01595,
  title  = {Position Heaps for Cartesian-tree Matching on Strings and Tries},
  author = {Akio Nishimoto and Noriki Fujisato and Yuto Nakashima and Shunsuke Inenaga},
  journal= {arXiv preprint arXiv:2106.01595},
  year   = {2021}
}
R2 v1 2026-06-24T02:46:51.643Z