Approximate Cartesian Tree Matching with One Difference
Bastien Auvray, Julien David, Samah Ghazawi, Richard Groult, Gad M. Landau, Thierry Lecroq
TL;DR
This work advances approximate Cartesian tree pattern matching with a single difference by introducing a flexible MetaAlgorithm that uses two linear representations (forward/reverse parent-distance and Skipped-number) to test CT-equivalence under one swap, mismatch, insertion, or deletion, achieving $O(nm)$ worst-case time with favorable average-case behavior. It complements this with an automaton-based method (inspired by PALP19) that builds a bounded-size automaton to recognize swap-affected representations, yielding $O((m^2+n)\log m)$ worst-case time and $O(m^2)$ space, scalable to more than one difference. The paper also provides deep structural analyses of how the PD and SN representations change under a swap, introduces a swap graph over Cartesian trees, and demonstrates practical performance through experiments supporting constant average-case behavior under random models. Together, these advances enable practical, theory-grounded approximate CTM with one difference and lay groundwork for extensions to broader error models and partial orders.
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.
