,
Ben Bals
,
Paweł Gawrychowski
,
Solon P. Pissis
,
Yuki Yonemoto
Creative Commons Attribution 4.0 International license
We consider directed graphs in which the nodes are labeled with strings. A walk in such a graph naturally corresponds to the concatenation of the visited nodes' labels. These graphs are widely used in bioinformatics to compactly describe large collections of highly similar genomes. Given such a graph G = (V,E) and a pattern of length m, we seek a walk whose corresponding string has an occurrence of the pattern. We call this the SMLG problem. Amir et al. [J. Algorithms, 2000] showed that SMLG can be solved in 𝒪(m |E| + N) time, where N is the total length of all node labels. Equi et al. [ACM Trans. Algorithms, 2023] showed that this is essentially optimal (under SETH).
The existing lower bound assumes that the sought walk is of length Θ(|V|). Thus, we might be able to bypass this lower bound by restricting the walk length to b-1, which naturally reduces to having as input a directed graph whose set of nodes is partitioned into b blocks. Then, we seek a walk in this graph that starts in the first block and ends in the last block. We call this the b-SMBG problem. Equi et al. [Algorithmica, 2023] showed that, if we impose no restriction on b, the existing algorithm of Amir et al. is essentially optimal for b-SMBG (again under SETH). We provide a more fine-grained classification that essentially settles the complexity of b-SMBG parameterized by b:
1) For b = 2, Pissis [SOSA 2025] already provided a simple 𝒪(m + |E|+N)-time algorithm.
2) We design a new 𝒪̃(m + |E| + N)-time algorithm for b = 3. As a direct implication of this result, the SMLG problem for b ≤ 3 (walks of length at most 2) also admits near-linear-time complexity.
3) There is no 𝒪((m |E|)^{1-ε} + N)-time combinatorial algorithm, for any b ≥ 4 and ε > 0.
4) There is an algorithm working in 𝒪(max(|V|, m)^ω+N) time, where ω is the matrix multiplication exponent, which is conditionally optimal for graphs with b ≥ 4 blocks.
5) Under SETH, no 𝒪((m |E|)^{1-ε} + N)-time algorithm exists, for any b = ω(log |V|) and ε > 0.
Although our motivation is primarily of a theoretical nature, we stress that our algorithms are simple to implement. As such, they may contribute to practical advancements in applications where the SMLG problem is an important primitive, such as in the analysis of pangenome graphs.
@InProceedings{angrick_et_al:LIPIcs.ESA.2026.105,
author = {Angrick, Sebastian and Bals, Ben and Gawrychowski, Pawe{\l} and Pissis, Solon P. and Yonemoto, Yuki},
title = {{String Matching in (Block) Graphs: A Full Classification by Walk Length}},
booktitle = {34th Annual European Symposium on Algorithms (ESA 2026)},
pages = {105:1--105:19},
series = {Leibniz International Proceedings in Informatics (LIPIcs)},
ISBN = {978-3-95977-445-1},
ISSN = {1868-8969},
year = {2026},
volume = {388},
editor = {Bille, Philip and Pettie, Seth and Storandt, Sabine},
publisher = {Schloss Dagstuhl -- Leibniz-Zentrum f{\"u}r Informatik},
address = {Dagstuhl, Germany},
URL = {https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.ESA.2026.105},
URN = {urn:nbn:de:0030-drops-272417},
doi = {10.4230/LIPIcs.ESA.2026.105},
annote = {Keywords: string algorithms, pattern matching, lower bounds, fine-grained complexity}
}