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 algorithm for solving approximate Cartesian tree pattern matching. We consider Cartesian tree pattern matching with one swap: given a pattern of length m and a text of length n we present two algorithms that find all the factors of the text that have the same Cartesian tree of the pattern after one transposition of two adjacent symbols. The first algorithm uses a characterization of a linear representation of the Cartesian trees called parent-distance after one swap and runs in time Theta(mn) using Theta(m) space. The second algorithm generates all the parent-distance tables of sequences that have the same Cartesian tree than the pattern after one swap. It runs in time O((m^2 + n)log m) and has O(m^2) space complexity.
翻译:笛卡尔树模式匹配旨在找出文本中所有与给定模式具有相同笛卡尔树的子串。针对精确匹配问题,已有理论及实践解决方案。本文首次提出解决近似笛卡尔树模式匹配的算法。我们考虑单次交换下的笛卡尔树模式匹配:给定长度为m的模式和长度为n的文本,提出两种算法,用于找出所有经一次相邻符号置换后与模式具有相同笛卡尔树的文本子串。第一种算法利用称为父距离的笛卡尔树线性表示在单次交换后的性质,时间复杂度为Θ(mn),空间复杂度为Θ(m)。第二种算法生成所有与模式经一次交换后具有相同笛卡尔树的序列的父距离表,时间复杂度为O((m²+n)log m),空间复杂度为O(m²)。