🤖 AI Summary
This paper studies Approximate Cartesian Tree Matching: finding all substrings of length $m$ in a text of length $n$ whose Cartesian trees differ from the pattern’s Cartesian tree in at most one structural aspect—e.g., a parent-child relationship or extremum position. We propose the first efficient algorithm supporting single-structural-difference matching, introducing a unified framework compatible with multiple definitions of structural difference. Our approach leverages a finite automaton-based design, ensuring extensibility to multi-difference settings. Theoretical analysis shows average-case linear time complexity under several stochastic models (e.g., random permutations, i.i.d. sequences), while worst-case runtime is $O(nm)$. The algorithm balances theoretical soundness with practical efficiency, establishing a new paradigm for robust structural matching of Cartesian trees.
📝 Abstract
Cartesian tree pattern matching consists of finding all the factors of a text that have the same Cartesian tree than a given pattern. There already exist theoretical and practical solutions for the exact case. In this paper, we propose the first algorithms for solving approximate Cartesian tree pattern matching with one difference given a pattern of length m and a text of length n. We present a generic algorithm that find all the factors of the text that have the same Cartesian tree of the pattern with one difference, using different notions of differences. We show that this algorithm has a O(nM) worst-case complexity and that, for several random models, the algorithm has a linear average-case complexity. We also present an automaton based algorithm, adapting [PALP19], that can be generalized to deal with more than one difference.