Optimal Square Detection Over General Alphabets

03/13/2023
by   Jonas Ellert, et al.
0

Squares (fragments of the form xx, for some string x) are arguably the most natural type of repetition in strings. The basic algorithmic question concerning squares is to check if a given string of length n is square-free, that is, does not contain a fragment of such form. Main and Lorentz [J. Algorithms 1984] designed an 𝒪(nlog n) time algorithm for this problem, and proved a matching lower bound assuming the so-called general alphabet, meaning that the algorithm is only allowed to check if two characters are equal. However, their lower bound also assumes that there are Ω(n) distinct symbols in the string. As an open question, they asked if there is a faster algorithm if one restricts the size of the alphabet. Crochemore [Theor. Comput. Sci. 1986] designed a linear-time algorithm for constant-size alphabets, and combined with more recent results his approach in fact implies such an algorithm for linearly-sortable alphabets. Very recently, Ellert and Fischer [ICALP 2021] significantly relaxed this assumption by designing a linear-time algorithm for general ordered alphabets, that is, assuming a linear order on the characters that permits constant time order comparisons. However, the open question of Main and Lorentz from 1984 remained unresolved for general (unordered) alphabets. In this paper, we show that testing square-freeness of a length-n string over general alphabet of size σ can be done with 𝒪(nlogσ) comparisons, and cannot be done with o(nlogσ) comparisons. We complement this result with an 𝒪(nlogσ) time algorithm in the Word RAM model. Finally, we extend the algorithm to reporting all the runs (maximal repetitions) in the same complexity.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
02/01/2023

Order-Preserving Squares in Strings

An order-preserving square in a string is a fragment of the form uv wher...
research
02/17/2021

Linear Time Runs over General Ordered Alphabets

A run in a string is a maximal periodic substring. For example, the stri...
research
06/29/2020

The Number of Repetitions in 2D-Strings

The notions of periodicity and repetitions in strings, and hence these o...
research
11/09/2021

Pattern Matching on Grammar-Compressed Strings in Linear Time

The most fundamental problem considered in algorithms for text processin...
research
10/17/2018

Fast and Longest Rollercoasters

For k≥ 3, a k-rollercoaster is a sequence of numbers whose every maximal...
research
05/25/2018

Algorithms for Anti-Powers in Strings

A string S[1,n] is a power (or tandem repeat) of order k and period n/k ...
research
06/03/2019

Direct Linear Time Construction of Parameterized Suffix and LCP Arrays for Constant Alphabets

We present the first worst-case linear time algorithm that directly comp...

Please sign up or login with your details

Forgot password? Click here to reset