---
title: Longest Unbordered Factor Problem
url: https://www.emergentmind.com/topics/longest-unbordered-factor-problem
type: topic
---

# Longest Unbordered Factor Problem

Searching arXiv for recent and foundational papers on the Longest Unbordered Factor Problem.
The **Longest Unbordered Factor Problem** asks, for a given string \(S\), for the maximum length of a factor of \(S\) that is unbordered, and often also for a factor attaining that maximum. If \(L(S)\) denotes the maximum length of an unbordered factor, then any factor of length \(L(S)\) is a maximal unbordered factor [1704.04472]. The problem lies at the intersection of combinatorics on words, periodicity, and string algorithms. It is closely tied to border structure, shortest periods, and the decomposition of strings into unbordered components, and it has been studied in worst-case, average-case, automatic-sequence, and compressed-string settings [1704.04472] [1805.09924] [2507.16285].

## 1. Definitions and formal setting

A **border** of a string is a non-empty proper prefix that is also a suffix [2305.03000] [1704.04472] [2507.16285]. Equivalently, a string \(S\) has a border of length \(\ell\), \(1 \le \ell \le n\), iff
\[
S[1,\ell]=S[n-\ell+1,n].
\]
A string is **unbordered** if it has no proper border [1704.04472]. A **factor** is a contiguous substring; for \(1 \le i \le j \le n\), \(S[i,j]\) denotes the factor \(S[i]\cdots S[j]\) [1704.04472]. The quantity
\[
L(S)
\]
denotes the maximum length of an unbordered factor of \(S\), and any unbordered factor of that length is called a **maximal unbordered factor** [1704.04472].

The problem is sometimes formulated globally and sometimes positionally. In the global formulation, the goal is to compute a longest unbordered factor of the input string [2507.16285]. In the positional formulation, the goal is to compute, for every starting position \(i\), the length of the longest unbordered factor starting at \(i\). This yields the **Longest Unbordered Factor Array**
\[
\operatorname{LUF}[i] = \max\{\, |u| : u \text{ is an unbordered factor of } w \text{ starting at position } i \,\},
\]
with global optimum
\[
\mu(w) = \max_{1 \le i \le n} \operatorname{LUF}[i].
\]
This stronger array problem was the focus of the quasilinear algorithm of Kociumaka et al. [1805.09924].

Borders and periods are equivalent in the standard way. An integer \(p>0\) is a period of \(S\in\Sigma^n\) if
\[
S[i]=S[i+p]\qquad \text{for }1\le i\le n-p.
\]
The shortest period is denoted \(per(S)\) [1704.04472]. A border of length \(b\) corresponds to period \(n-b\), so a string is unbordered iff its minimum period is its full length [1704.04472] [1805.09924]. This duality is fundamental throughout the literature.

## 2. Structural combinatorics of borders and unbordered factors

Several structural facts about borders are central to LUF reasoning. A useful representation is the **Prefix Border Array**, denoted \(\LPS[1..n]\), where
\[
\LPS[i] = j \iff \text{the longest proper prefix of } w_1\cdots w_i \text{ that is also a suffix has length } j.
\]
In particular,
\[
\LPS[i]=0 \iff w_1\cdots w_i \text{ is unbordered.}
\]
This makes unborderedness equivalent to zero longest proper border length [2305.03000].

Two combinatorial lemmas are especially important. First, if \(w\) is bordered and \(u\) is a border of \(w\), then \(u\) is the shortest border of \(w\) **if and only if** \(u\) is unbordered [2305.03000]. Thus every bordered word has a minimal border, and that minimal border is necessarily unbordered. Second, if \(u\) is the shortest border of a length-\(n\) bordered word \(w\), then
\[
|u| \leq \frac{n}{2}.
\]
If the shortest border were longer than \(n/2\), the overlap of its prefix and suffix occurrences would force \(u\) itself to be bordered, contradicting the previous lemma [2305.03000]. This half-length property is a basic pruning principle: any bordered candidate factor has an unbordered border witness of length at most half its length.

The same phenomenon appears in the probabilistic analysis of random strings. If \(F(S)\) denotes the length of the shortest border, then
\[
P[F(S)=\ell]=0\quad \text{ if }\tfrac12 n<\ell<n,
\]
because any border of length \(\ell>n/2\) induces a shorter border of length \(2\ell-n\) [1704.04472]. This observation underlies both combinatorial and average-case arguments.

The literature also relates maximal unbordered factors to minimal period. If \(b(S)\) denotes the length of the maximal unbordered factor and \(\pi(S)\) the minimal period, then Ehrenfeucht and Silberger showed that if the minimal period of \(S\) is \(< \frac n2\), then
\[
b(S)=\pi(S).
\]
However, the converse regime is subtler. Assous and Pouzet gave a counterexample of length
\[
n = 7m+10
\]
for which
\[
b(S)=3m+6 \le \frac{3}{7}n+2 < \frac n2,
\qquad
\pi(S)=4m+7 \ne b(S),
\]
showing that \(b(S)\) and \(\pi(S)\) need not coincide even when \(b(S)<n/2\) [1504.07406]. Holub and Nowotka later showed that if
\[
b(S)\le \frac{3}{7}n,
\]
then
\[
b(S)=\pi(S),
\]
and that this bound is tight [1504.07406]. This rules out a simplistic identification of LUF length with shortest period in general.

## 3. Algorithmic foundations and worst-case complexity

A direct algorithmic primitive is border computation via KMP-style arrays. For a word \(w=w_1w_2\cdots w_n\), the unbordered prefix indicator \(a[1..n]\), defined by
\[
a[i]=1 \iff w_1w_2\cdots w_i \text{ is unbordered},
\]
can be computed in \(O(n)\) time by computing \(\LPS\) and testing \(\LPS[i]=0\) [2305.03000]. Likewise, the full border indicator of a word can be computed in \(O(n)\) time [2305.03000]. These are foundational tools for LUF-style algorithms, because they reduce border questions to linear-time prefix-function and border-chain computations.

A straightforward baseline algorithm computes, for every suffix \(S[i..n]\), its border array; prefixes with border-array value \(0\) are exactly unbordered prefixes, so scanning all suffixes inspects all factors. This yields \(O(n^2)\) time [1504.07406]. The same paper proposed a deterministic modification: process suffixes from longest to shortest, maintain the best MUF length \(L\), and stop once the current suffix length is at most \(L\). For a string \(S\), this runs in
\[
O((n-b(S))\cdot n),
\]
where \(b(S)\) is the length of the maximal unbordered factor [1504.07406].

The first substantial worst-case improvement before quasilinear time was the \(O(n^{1.5})\)-time method of Gawrychowski et al., cited as the previous best worst-case algorithm on integer alphabets [1805.09924]. Kociumaka et al. then gave the first quasilinear algorithm for the **Longest Unbordered Factor Array** on general alphabets:
\[
O(n\log n)\text{ time w.h.p.}
\]
and deterministically
\[
O(n\log n\log^2\log n).
\]
This computes the entire \(\operatorname{LUF}[1..n]\) array, not merely the global optimum [1805.09924].

The algorithmic framework uses the **Longest Successor Factor** arrays. For each position \(i\),
\[
\textsf{LSF}_{\ell}[i]
\]
is the length of the longest factor starting at \(i\) that occurs again somewhere to its right, and
\[
\textsf{LSF}_{r}[i]
\]
is the position of the last occurrence of that factor [1805.09924]. The algorithm processes positions from right to left and splits into three cases: positions with no successor repetition, positions whose repeated part is shorter than the longest unbordered factor at the referred position, and a hard case resolved through the notion of a **hook** [1805.09924].

For a position \(j\), the hook \(H_j\) is the smallest position \(q\) such that \(w[q..j-1]\) can be decomposed into unbordered prefixes of \(w[j..n]\) [1805.09924]. In the hard case,
\[
\operatorname{LUF}[i] = \begin{cases} H_j - i, & i < H_j,\[1mm] \operatorname{LUF}[j], & i \ge H_j. \end{cases}
\]
The efficiency comes from combining this combinatorial description with prefix-suffix query data structures and a stack-based memoization of partial hook information. The resulting total hook work is \(O(n\log n)\), and the algorithm’s \(O(n\log n)\) upper bound is tight for its stack-size analysis on an infinite family of binary words [1805.09924].

The main open worst-case question remains whether LUF can be solved in \(O(n)\) time on ordinary strings. The compressed-string literature makes explicit that the true open problem is whether LUF can be solved in \(O(n)\) time on plain strings [2507.16285].

## 4. Average-case theory and relation to shortest period

Average-case analysis for uniformly random strings has been especially successful. Loptev, Kucherov, and Starikovskaya proved a lower bound implying that for large alphabets the expected maximum unbordered-factor length is close to \(n\), and conjectured
\[
E[L(S)] = n-O(1)
\]
for a uniformly random string over a fixed non-unary alphabet [1704.04472]. That conjecture was later confirmed and sharpened: for a uniformly random length-\(n\) string over a fixed alphabet \(\Sigma\) of size \(\sigma\ge 2\),
\[
E[L(S)] = n-\Theta(\sigma^{-1}),
\]
with the theorem stated in the paper as
\[
E[L(S)]=n - O(\sigma^{-1}),
\]
and with the abstract giving the final asymptotic as \(n-\Theta(\sigma^{-1})\) [1704.04472].

The same work establishes concentration. For each \(\delta>0\), the probability of
\[
L(S)=n-O(\log_\sigma \delta^{-1})
\]
is at least \(1-\delta\) [1704.04472]. Equivalently, the deficiency
\[
\Delta_n := |S|-L(S)
\]
has an exponentially decaying tail. The proof proceeds by bounding the moment generating function
\[
M_{\Delta_n}(t)=E[e^{t\Delta_n}]
\]
uniformly in \(n\), conditioning on the shortest border length, and exploiting the impossibility of a shortest border length in \((n/2,n)\) [1704.04472].

These results imply that in a uniformly random string, the longest unbordered factor is typically extremely close to the full string length. They also imply algorithmic consequences. Loptev et al. had an algorithm running in
\[
O(n(n-L(S)+1))
\]
worst-case time, which becomes
\[
O(n)
\]
on average once \(E[n-L(S)] = O(1)\) is known [1704.04472]. More significantly, the same paper establishes an average-case equivalence between computing the LUF length and computing the shortest period. Specifically, it proves:

1. The problem of computing \(L(S)\) can be reduced in \(O(\log_{\sigma}n)\) expected time to the problem of computing \(per(S')\) for a fixed factor \(S'\) of \(S\).
2. The problem of computing \(per(S)\) can be reduced in \(O(1)\) expected time to the problem of computing \(L(S)\) [1704.04472].

Because Czumaj and Gąsieniec had proved for shortest-period computation on uniformly random strings the bounds
\[
\Omega(\sqrt{n})
\qquad\text{and}\qquad
O(\sqrt{n\log_\sigma n}),
\]
these transfer to maximal unbordered factors [1704.04472]. As a result, the average-case running time for computing a maximal unbordered factor lies in
\[
\Omega (\sqrt{n}) \cap O (\sqrt{n \log_\sigma n}),
\]
which is substantially below linear [1704.04472].

Earlier probabilistic work had already shown that the expected MUF length is large. Over an alphabet of size \(\sigma \ge 2\), the expected length of the maximal unbordered factor is at least
\[
n\cdot (1 - \xi(\sigma) \cdot \sigma^{-4}) + O(1),
\]
where
\[
\xi(2) = 8
\]
and for \(\sigma > 2\),
\[
\xi(\sigma) =
\frac{2\sigma^3 - 2\sigma^2}{(\sigma-2)(\sigma^2 - 2\sigma +2)}.
\]
For \(\sigma\ge 5\), this yields the corollary
\[
0.99 n
\]
for sufficiently large \(n\) [1504.07406]. That lower bound motivated the suffix-border-array early-stopping algorithm, whose expected running time under the uniform distribution over \(A^n\) is
\[
O\!\left(\frac{n^2}{\sigma^4}\right)
\]
[1504.07406]. Historically, this average-case lower bound preceded the sharper \(n-\Theta(\sigma^{-1})\) result [1704.04472].

## 5. Counting, automata, and combinatorial enumeration

Although not direct LUF algorithms, counting results and enumeration methods illuminate how common unbordered words are and how border structure propagates. Over a \(k\)-letter alphabet, if \(u_k(n)\) is the number of unbordered words of length \(n\), then the number of bordered words is
\[
k^n-u_k(n).
\]
The literature cited in the ranking and unranking work states that Nielsen showed both
\[
u_k(n)=\Theta(k^n)
\qquad\text{and}\qquad
k^n-u_k(n)=\Theta(k^n),
\]
so a constant fraction of all length-\(n\) words are unbordered, and also a constant fraction are bordered [2305.03000]. This helps explain why long unbordered factors are statistically common.

A more refined combinatorial object is
\[
B_k(u,n),
\]
the number of length-\(n\) bordered words over \(\Sigma_k\) having \(u\) as a prefix. For \(u\) of length \(p\), with unbordered prefix indicator \(a[1..p]\) and border indicator \(b[1..p]\), the recurrence is
\[
B_k(u,n) = \begin{cases} \sum\limits_{i=1}^{n-p}a[i]k^{n-p-i} + \sum\limits_{i=n-p+1}^{\lfloor n/2\rfloor} a[i]b[i-(n-p)], & \text{if } n \leq 2p; \\[1ex] \sum\limits_{i=1}^p a[i] k^{n-p-i} + \sum\limits_{i=p+1}^{\lfloor n/2\rfloor} (k^{i-p} - B_k(u,i))k^{n-2i}, & \text{otherwise.} \end{cases}
\]
This recurrence classifies bordered words by the length of their shortest border, using the facts that shortest borders are unbordered and have length at most half [2305.03000]. While this is not an LUF algorithm, it gives a structural decomposition directly relevant to border-based pruning arguments.

In automatic-sequence settings, counting methods become automata-theoretic. For the Thue–Morse sequence \({\bf t}\), the number \(f(n)\) of distinct unbordered factors of length \(n\) is shown to be a \(2\)-regular sequence with explicit recurrences [1211.1301]. The paper constructs a **23-state automaton** accepting pairs \((n,i)_2\) such that there is a novel unbordered factor of length \(n\) beginning at position \(i\), and then deduces that \(f\) is \(2\)-regular [1211.1301]. Its main asymptotic theorem states
\[
f(n)\le n \qquad \text{for } n\ge 4,
\]
and also
\[
f(n)=n \quad \text{infinitely often},
\]
with the explicit identity
\[
f(3\cdot 2^i)=3\cdot 2^i \qquad (i\ge 1)
\]
[1211.1301].

The same work also cites a characterization of existence for Thue–Morse:
\[
{\bf t}\text{ has an unbordered factor of length }n
\iff
(n)_2 \notin 1(01^*0)^*10^*1.
\]
This does not solve the finite-string LUF problem, but it shows that, in automatic sequences, existence-at-length can be regular in the base-\(k\) representation of the length [1211.1301]. Such results are relevant for bounded-prefix or sequence-specific variants of longest-unbordered-factor questions.

## 6. Compressed-string variants and run-length encoding

The LUF problem has also been studied in compressed-string processing, particularly for run-length encoded strings. In the RLE model, a string \(T\) is represented as
\[
rle(T)=R_1R_2\cdots R_m,
\]
where each run \(R_i=c^{e_i}\) is a maximal block of identical characters, with uncompressed length
\[
n=\sum_{i=1}^m e_i
\]
and compressed size \(m=r(T)\) [2507.16285]. A factor is **RLE-bounded** if it starts at some run boundary and ends at some run boundary [2507.16285].

The main structural observation is:
\[
\textbf{Lemma 1.}\quad \text{Let }u\text{ be a string of length at least two, and let }a=u[1],\, b=u[|u|]. \text{ If }u\text{ is unbordered, then both }au\text{ and }ub\text{ are also unbordered.}
\]
Because extending an unbordered factor within a run preserves unborderedness, every longest unbordered factor of a non-unary string can be extended to run boundaries. Consequently, every longest unbordered factor is **RLE-bounded** [2507.16285]. This is the core compressed-structure theorem in the paper.

Using this reduction, the paper gives an algorithm that, given an RLE encoded string of RLE size \(m\), computes the set of longest unbordered factors in
\[
O(m\sqrt{m}\log^2 m)\text{ time using } O(m\log^2 m)\text{ space,}
\]
equivalently
\[
O(m^{1.5}\log^2 m)\text{ time and }O(m\log^2 m)\text{ space.}
\]
This adapts the candidate-elimination strategy of the older \(O(n^{1.5})\)-time algorithm to the run-length encoded setting [2507.16285].

The algorithm introduces run-based tools, including the **RLE shortest border array**
\[
rSBord[i]=\text{the RLE size of the shortest border of }T[1..end_i],
\]
computable in
\[
O(m\log m)\text{ time}
\]
[2507.16285]. It partitions the runs into \(\lceil \sqrt m\rceil\) blocks, treats borders of RLE size at most \(\sqrt m\) as short, and uses two principal subroutines: one for finding longest unbordered factors of small RLE size and one for generating and then filtering candidates that have no short border but may have a long border [2507.16285]. Long-border filtering relies on an **RLE pseudo period**
\[
pp(w)=r-b,
\]
where \(r=r(w)\) and \(b\) is the RLE size of the longest border of \(w)\) [2507.16285].

This compressed result does not improve the worst-case uncompressed bound when \(m=\Theta(n)\), since it becomes \(O(n^{1.5}\log^2 n)\), worse than \(O(n\log n)\) [2507.16285]. Its significance is instead that it is the first nontrivial LUF algorithm whose complexity is expressed in terms of the RLE size rather than the uncompressed length.

## 7. Scope, variants, and research directions

The LUF problem has several distinct but related variants. The classical finite-string optimization problem asks for one longest unbordered factor or its length [1704.04472] [2507.16285]. The array variant asks for the longest unbordered factor starting at each position [1805.09924]. Average-case work studies random strings under the uniform distribution over a fixed alphabet [1504.07406] [1704.04472]. Automata-theoretic work studies existence and counting for structured infinite words such as Thue–Morse and period-doubling sequences [1211.1301]. Compressed-string work studies the same optimization problem under succinct input models such as RLE [2507.16285].

A common misconception is to identify longest unbordered factor length with shortest period outright. The literature shows instead a more nuanced relationship: \(L(S)\le per(S)\) for every string [1704.04472], the two quantities coincide in certain small-period or small-\(b(S)\) regimes [1504.07406], and in the random-input setting they are equivalent up to very small average-case reduction overheads [1704.04472]. But they are not identical in general, as the Assous–Pouzet counterexample demonstrates [1504.07406].

Another important distinction is between counting and optimization. Enumeration results such as \(u_k(n)=\Theta(k^n)\), the recurrence for \(B_k(u,n)\), or the \(2\)-regular recurrences for the Thue–Morse counting function \(f(n)\) do not directly compute LUF on an arbitrary finite input, but they provide structural information about border witnesses, abundance of unbordered words, and regularity phenomena that inform algorithm design [2305.03000] [1211.1301].

The main unresolved algorithmic question highlighted in the literature is whether LUF can be solved in linear time on ordinary strings [2507.16285]. The quasilinear algorithm of Kociumaka et al. remains the benchmark worst-case result on general alphabets [1805.09924], while the RLE result suggests that compressed representations may admit further specialized advances [2507.16285]. A plausible implication is that progress may continue along two tracks: improved border-sensitive decompositions for the uncompressed problem, and structure-exploiting reductions for compressed or highly repetitive inputs.

Source: https://www.emergentmind.com/topics/longest-unbordered-factor-problem