English

Pattern Matching with Mismatches and Wildcards

Data Structures and Algorithms 2024-05-22 v2

Abstract

In this work, we address the problem of approximate pattern matching with wildcards. Given a pattern PP of length mm containing DD wildcards, a text TT of length nn, and an integer kk, our objective is to identify all fragments of TT within Hamming distance kk from PP. Our primary contribution is an algorithm with runtime O(n+(D+k)(G+k)n/m)O(n+(D+k)(G+k)\cdot n/m) for this problem. Here, GDG \le D represents the number of maximal wildcard fragments in PP. We derive this algorithm by elaborating in a non-trivial way on the ideas presented by [Charalampopoulos et al., FOCS'20] for pattern matching with mismatches (without wildcards). Our algorithm improves over the state of the art when DD, GG, and kk are small relative to nn. For instance, if m=n/2m = n/2, k=G=n2/5k=G=n^{2/5}, and D=n3/5D=n^{3/5}, our algorithm operates in O(n)O(n) time, surpassing the Ω(n6/5)\Omega(n^{6/5}) time requirement of all previously known algorithms. In the case of exact pattern matching with wildcards (k=0k=0), we present a much simpler algorithm with runtime O(n+DGn/m)O(n+DG\cdot n/m) that clearly illustrates our main technical innovation: the utilisation of positions of PP that do not belong to any fragment of PP with a density of wildcards much larger than D/mD/m as anchors for the sought (approximate) occurrences. Notably, our algorithm outperforms the best-known O(nlogm)O(n\log m)-time FFT-based algorithms of [Cole and Hariharan, STOC'02] and [Clifford and Clifford, IPL'04] if DG=o(mlogm)DG = o(m\log m). We complement our algorithmic results with a structural characterization of the kk-mismatch occurrences of PP. We demonstrate that in a text of length O(m)O(m), these occurrences can be partitioned into O((D+k)(G+k))O((D+k)(G+k)) arithmetic progressions. Additionally, we construct an infinite family of examples with Ω((D+k)k)\Omega((D+k)k) arithmetic progressions of occurrences, leveraging a combinatorial result on progression-free sets [Elkin, SODA'10].

Keywords

Cite

@article{arxiv.2402.07732,
  title  = {Pattern Matching with Mismatches and Wildcards},
  author = {Gabriel Bathie and Panagiotis Charalampopoulos and Tatiana Starikovskaya},
  journal= {arXiv preprint arXiv:2402.07732},
  year   = {2024}
}

Comments

This version contains a fix in the proof of Theorem 3.10 and other minor changes

R2 v1 2026-06-28T14:46:06.924Z