English

String Matching in (Block) Graphs: A Full Classification by Walk Length

Data Structures and Algorithms 2026-07-30 v1

Abstract

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)G=(V,E) and a pattern of length mm, 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 O(mE+N)\mathcal{O}(m|E| + N) time, where NN 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)\Theta(|V|). Thus, we might be able to bypass this lower bound by restricting the walk length to b1b-1, which naturally reduces to having as input a directed graph whose set of nodes is partitioned into bb 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 bb-SMBG problem. We provide a more fine-grained classification that essentially settles the complexity of bb-SMBG parameterized by bb: (1) We give a near-linear-time algorithm for b=3b=3. (2) We show that there is no combinatorial algorithm improving over the state-of-the-art O(mE+N)\mathcal{O}(m|E| + N) bound for any b4b\ge 4. (3) We also present a fast matrix multiplication-based algorithm yielding an improvement for bO(1)b \in \mathcal{O}(1), which is conditionally optimal. (4) Finally, we show that under SETH, for any bω(logV)b \in \omega(\log |V|), no algorithm can improve over the state of the art.

Cite

@article{arxiv.2607.28159,
  title  = {String Matching in (Block) Graphs: A Full Classification by Walk Length},
  author = {Sebastian Angrick and Ben Bals and Paweł Gawrychowski and Solon P. Pissis and Yuki Yonemoto},
  journal= {arXiv preprint arXiv:2607.28159},
  year   = {2026}
}

Comments

ESA 2026