English

String Matching with a Dynamic Pattern

Data Structures and Algorithms 2025-06-16 v1 Discrete Mathematics

Abstract

In this work, we tackle a natural variation of the String Matching Problem on the case of a dynamic pattern, that is, given a static text TT and a pattern PP, we want to support character additions and deletions to the pattern, and after each operation compute how many times it occurs in the text. We show a simple and practical algorithm using Suffix Arrays that achieves O(logT)\mathcal O(\log |T|) update time, after O(T)\mathcal O(|T|) preprocess time. We show how to extend our solution to support substring deletion, transposition (moving a substring to another position of the pattern), and copy (copying a substring and pasting it in a specific position), in the same time complexities. Our solution can also be extended to support an online text (adding characters to one end of the text), maintaining the same amortized bounds.

Keywords

Cite

@article{arxiv.2506.11318,
  title  = {String Matching with a Dynamic Pattern},
  author = {Bruno Monteiro and Vinicius dos Santos},
  journal= {arXiv preprint arXiv:2506.11318},
  year   = {2025}
}