Substring Counting with Insertions
Substring counting is a classical algorithmic problem with numerous solutions that achieve linear time complexity. In this paper, we address a variation of the problem where, given three strings p, t, and s, we are interested in the number of occurrences of p in all strings that would result from inserting t into s at every possible position. Essentially, we are solving several substring counting problems of the same substring p in related strings. We give a detailed description of several conceptually different approaches to solving this problem and conclude with an algorithm that has a linear time complexity. The solution is based on a recent result from the field of substring search in compressed sequences and exploits the periodicity of strings. We also provide a self-contained implementation of the algorithm in C++ and experimentally verify its behavior, chiefly to demonstrate that its running time is linear in the lengths of all three input strings.
Authors
- Janez Brank
- Tomaž Hočevar (ORCID: https://orcid.org/0000-0002-7998-2638)
Institutions
- University of Ljubljana (SI)
- Jožef Stefan Institute (SI)
Publication Details
- Journal
- Algorithms
- Published
- 2025-06-19
- DOI
- https://doi.org/10.3390/a18060371
- Primary Topic
- Algorithms and Data Compression
- Type
- article
- Field-Weighted Citation Impact
- 0.00
Funders
- Javna Agencija za Raziskovalno Dejavnost RS