paper

Fast Computation of -Runs, Parameterized Squares, and Other Generalised Squares

arXiv:2509.02179

Abstract

A -mismatch square is a string of the form where and are two equal-length strings that have at most mismatches. Kolpakov and Kucherov [Theor. Comput. Sci., 2003] defined two notions of -mismatch repeats, called -repetitions and -runs, each representing a sequence of consecutive -mismatch squares of equal length. They proposed algorithms for computing -repetitions and -runs working in time for a string of length over an integer alphabet, where is the number of the reported repeats. We show that , both in case of -repetitions and -runs, which implies that the complexity of their algorithms is actually . We apply this result to computing parameterized squares. A parameterized square is a string of the form such that and parameterized-match, i.e., there exists a bijection on the alphabet such that . Two parameterized squares and are equivalent if they parameterized match. Recently Hamai et al. [SPIRE 2024] showed that a string of length over an alphabet of size contains less than non-equivalent parameterized squares, improving an earlier bound by Kociumaka et al. [Theor. Comput. Sci., 2016]. We apply our bound for -mismatch repeats to propose an algorithm that reports all non-equivalent parameterized squares in time. We also show that the number of non-equivalent parameterized squares can be computed in time. This last algorithm applies to squares under any substring compatible equivalence relation and also to counting squares that are distinct as strings. In particular, this improves upon the -time algorithm of Gawrychowski et al. [CPM 2023] for counting order-preserving squares that are distinct as strings if .

Accepted to ESA 2025