---
title: Shortest Absent Substring (SAS) Algorithms
url: https://www.emergentmind.com/topics/shortest-absent-substring-sas
type: topic
---

# Shortest Absent Substring (SAS) Algorithms

Searching arXiv for recent and foundational papers on shortest absent substrings and closely related minimal absent word results.
A **shortest absent substring (SAS)** of a string \(S\) is a string of minimum length that does not occur in \(S\) as a substring. For \(S \in [0,\sigma)^n\), a string \(P\) is absent iff \(|Occ(P,S)|=0\), and \(P\) is a SAS iff it is absent and no shorter absent string exists. In the packed-string word-RAM setting, the 2026 work "Faster Algorithms for Shortest Unique or Absent Substrings" establishes that SAS can be computed in \(\mathcal{O}(n\log \sigma/\sqrt{\log n})\) time by reducing absence to a shortest exclusivity problem and using de Bruijn sequences as a compact witness universe [2605.04826]. Combinatorially, every SAS is a minimal absent word, and the set of SASs is exactly the minimum-length layer of \(MAW(S)\) [2105.08496].

## 1. Definition and formal problem statement

Let the input be a string
\[
S \in [0,\sigma)^n
\]
of length \(n\) over the integer alphabet \([0,\sigma)\). A string \(P\) is **absent** from \(S\) iff
\[
|Occ(P,S)| = 0.
\]
A string \(P\) is a **shortest absent substring** iff
\[
|Occ(P,S)|=0
\quad\text{and}\quad
\nexists P' : |P'|<|P|,\ |Occ(P',S)|=0.
\]

The formal output specification used in the packed-word-RAM treatment is stronger than returning only the minimum length: given packed \(S\), the algorithm returns \(i,j\in \mathbb Z_{\ge 0}\) and \(c\in\Sigma\) such that
\[
P = S[i..j]\cdot c
\]
is a shortest absent substring of \(S\) [2605.04826]. Thus the witness is encoded as a substring of the input plus one appended character.

SAS is closely related to two adjacent notions. First, a **shortest unique substring (SUS)** is a substring occurring exactly once and having minimum length among such substrings. Second, a **minimal absent word (MAW)** is an absent string all of whose proper substrings occur. Every SAS is therefore a MAW, because if a proper substring of a shortest absent string were also absent, that proper substring would be a shorter absent string. Equivalently,
\[
SAS(S) = \{w \in MAW(S) \mid |w| = \min_{u \in MAW(S)} |u|\}
\]
[2105.08496].

## 2. Classical formulation and packed-string motivation

Classically, SAS is folklore-solvable in \(O(n)\) time using the suffix tree \(ST(S)\). The standard idea is that if a node \(u\) of the suffix tree has fewer than \(\sigma\) outgoing edges, then for every missing outgoing first letter \(c\), the string \(str(u)\cdot c\) is absent from \(S\); the shortest absent strings arise from minimum-depth nodes with a missing edge. This yields extraction of all SASs in \(O(n+|\mathrm{output}|)\) time [2605.04826].

The packed-string model changes the cost baseline. In the unit-cost word-RAM with word size \(w=\Theta(\log n)\), a string over alphabet \([0,\sigma)\) can be packed with \(\Theta(\log_\sigma n)\) letters per machine word. A length-\(n\) string therefore occupies
\[
O\!\left(1+\frac{n}{\log_\sigma n}\right)
=
O\!\left(\frac{n\log \sigma}{\log n}+1\right)
\]
machine words and can be read in
\[
O\!\left(\frac{n\log \sigma}{\log n}\right)
\]
time [2605.04826]. For small alphabets, simply reading the packed input is already sublinear in \(n\). The folklore suffix-tree solution remains \(O(n)\), so its running time is not necessarily input-optimal in this model.

The 2026 result answers the resulting question affirmatively: SAS can be computed in
\[
\mathcal{O}(n \log \sigma / \sqrt{\log n})
\]
time in the packed-string word-RAM model [2605.04826]. The same asymptotic bound applies for integer alphabets \([0,\sigma)\) with \(\sigma=n^{O(1)}\). The asymptotic gain is strongest when \(\sigma\) is small; the bound is asymptotically faster than \(O(n)\) whenever
\[
\log \sigma = o(\sqrt{\log n}),
\]
and for constant alphabets it becomes
\[
O(n/\sqrt{\log n}).
\]

## 3. Reduction to exclusivity and the de Bruijn construction

The faster SAS algorithm is not obtained by refining suffix-tree traversal. Instead, it proceeds through an auxiliary two-string problem, **Shortest Exclusive Substring**: given strings \(S_1,S_2\), find a shortest substring of \(S_1\) that does not occur in \(S_2\). The paper proves that any instance of Shortest Exclusive Substring can be solved in
\[
O(n\log \sigma/\sqrt{\log n})
\]
time, and then reduces SAS to this problem by choosing \(S_1\) to contain a sufficiently rich set of candidate strings [2605.04826].

The exclusive-substring algorithm reuses the SUS framework with the same four-case decomposition:

1. short substrings;
2. medium-length aperiodic substrings;
3. long aperiodic substrings;
4. periodic substrings.

The same principal tools reappear with an exclusive interpretation. **Synchronizing sets** anchor sufficiently long aperiodic candidates in both \(S_1\) and \(S_2\). **Analysis of runs** groups periodic candidates by Lyndon root or sparse-Lyndon root. **Wavelet trees** organize prefix/suffix pair families, now with an origin bit distinguishing the two strings. Several subproblems are reduced geometrically: the SUS primitive **Minimum Skyline Point** is replaced by **Minimum Exclusive Point**, which asks for a point dominated by at least one point of \(P_1\) and by no point of \(P_2\), minimizing \(x+y\). The key lemma states that Minimum Exclusive Point can be solved in
\[
O(|P_1| + |P_2|)
\]
time when the point sets are given sorted by one coordinate [2605.04826].

The SAS-specific ingredient is the use of **de Bruijn sequences**. A de Bruijn sequence of order \(k\) over alphabet \(\Sigma\) of size \(\sigma\) is a string of length
\[
\sigma^k + k - 1
\]
in which every string from \(\Sigma^k\) occurs exactly once. The paper proves that a packed de Bruijn sequence of order \(k\) over \([0,\sigma)\) for \(\sigma\ge 2\) can be constructed in
\[
O(\sigma^k/k)=O(n/\log_\sigma n)
\]
time, and its prefix of length \(\ell\) can be constructed in
\[
O(\ell/\log_\sigma n + 1)
\]
time [2605.04826].

Set
\[
k := \lfloor \log_\sigma n \rfloor + 1.
\]
Since \(\sigma^k > n\), the string \(S\) cannot contain all \(\sigma^k\) strings of length \(k\), so every SAS has length at most \(k\). The algorithm then builds a de Bruijn sequence \(S_1\) of order \(k-1\) and runs Shortest Exclusive Substring on \((S_1,S)\). If the result has length at most \(k-1\), it is a SAS. Otherwise the SAS length is \(k\). At that point, either a full de Bruijn sequence of order \(k\) is constructed when \(\sigma^k = O(n)\), or only a prefix \(S'_1\) of length \(n+1\) is constructed when \(\sigma^k=\omega(n)\). In the latter case, the counting argument is explicit: \(S'_1\) contains
\[
n-k+2
\]
distinct substrings of length \(k\), while \(S\) contains at most
\[
n-k+1
\]
such substrings, so at least one length-\(k\) substring of \(S'_1\) is absent from \(S\) [2605.04826].

## 4. Complexity, reconstruction, and open questions

The headline theorem is that a shortest absent substring of a packed string \(S\) of length \(n\) over integer alphabet \([0,\sigma)\) can be computed in
\[
O(n\log \sigma/\sqrt{\log n})
\]
time [2605.04826]. The construction of the relevant de Bruijn sequence or prefix is lower-order at the scales used, so the Shortest Exclusive Substring calls dominate the total running time.

The algorithm is deterministic in the SAS result as presented. The output is an actual absent string, not just its length. In the direct SAS formulation this is returned as \(i,j,c\) with
\[
P=S[i..j]\cdot c.
\]
In the reduction through exclusivity, the exclusive substring found in the de Bruijn sequence is itself an absent string of \(S\), and because the de Bruijn reference strings are generated explicitly, the witness can be reconstructed directly from the reported position and length [2605.04826].

The paper does not state a single consolidated standalone space theorem for the full SAS algorithm. It gives component-level bounds instead; for example, the long aperiodic exclusive case states that the relevant tries occupy
\[
O(n\log \sigma/\log^4 n)
\]
space. The principal contribution is the time improvement rather than a unified space bound [2605.04826].

Several limitations remain explicit. The result is stated in the packed word-RAM model for integer alphabets with \(\sigma=n^{O(1)}\). It improves on \(O(n)\) but does not reach the packed-input reading bound
\[
O(n\log \sigma/\log n).
\]
The paper also notes that proving conditional lower bounds for SUS and SAS appears challenging, and leaves open whether the new bounds can be improved further or shown conditionally optimal [2605.04826].

## 5. Relation to minimal absent words and indexed query variants

The MAW viewpoint is the standard combinatorial envelope for SAS. A word \(w\) is a minimal absent word for \(S\) iff \(w\) does not occur in \(S\) but \(w[2..]\) and \(w[..|w|-1]\) do occur; equivalently, all proper substrings occur. This immediately implies that shortest absent substrings are precisely minimum-length MAWs [2105.08496].

That equivalence supports stronger query models. In the **internal shortest absent word** problem, one preprocesses a text \(T\) so that for any query range \([a,b]\), one can return a shortest string over the alphabet that does not occur in \(T[a..b]\). For a string \(T\) of length \(n\) over \(\Sigma \subseteq \{1,2,\ldots,n^{O(1)}\}\) of size \(\sigma\), the paper "Internal Shortest Absent Word Queries in Constant Time and Linear Space" gives an \(O(n)\)-space data structure with \(O(1)\) query time and \(O(n\log_\sigma n)\) construction time [2106.01763].

The core quantity there is the shortest absent-word length
\[
\lambda(T)=\min\{j\ge 1 : S_T(j)<\sigma^j\},
\]
where \(S_T(j)\) is the number of distinct length-\(j\) substrings of \(T\). This yields
\[
\lambda(T)\in [1,\lfloor \log_\sigma n\rfloor].
\]
The data structure returns a constant-space representation of the answer, either as a range \([i,j]\) meaning \(T[i..j]\), or as a range \([i,j]\) and a letter \(\alpha\), meaning \(T[i..j]\alpha\) [2106.01763]. This representation is directly aligned with the witness format used in the packed-word-RAM SAS algorithm.

## 6. Sliding-window, compressed-space, and neighboring formulations

The sliding-window literature studies how the MAW set changes when a fixed-length window shifts over a larger text. Since SAS is the minimum-length layer of \(MAW(\cdot)\), these results bound the instability of shortest absent substrings indirectly. For a window of length \(d\), the total number of MAW changes over all adjacent windows is
\[
\mathcal{S}(T,d)\in O(\min\{d,\sigma\}n),
\]
and this bound is tight when \(n-d\in\Omega(n)\). At a single shift, the worst-case symmetric difference is \(\Theta(d)\). For binary alphabets, the one-step bound tightens to
\[
\max\{3,d\}
\]
[2105.08496]. Earlier sliding-window work had already shown the contrast with minimal unique substrings: MUSs can change by only \(O(1)\) per shift, whereas MAWs may change by \(\Theta(d)\) [1909.02804]. A plausible implication is that sliding-window SAS maintenance is structurally closer to MAW maintenance than to MUS maintenance.

Compressed representations lead to different tradeoffs. For run-length encoded strings \(rle(T)=a_1^{p_1}\cdots a_m^{p_m}\), the paper "Minimal Absent Words on Run-Length Encoded Strings" gives an \(O(m)\)-space data structure that can output all MAWs in \(O(|MAW(T)|)\) time, with build time \(O(m\log m)\). A direct consequence is that SAS can be obtained by enumerating MAWs and selecting a shortest one, yielding \(O(m\log m + |MAW(T)|)\) time and \(O(m)\) space [2202.13591].

For highly repetitive strings, CDAWG-based compression provides a different route. "Computing Minimal Absent Words and Extended Bispecial Factors with CDAWG Space" outputs all non-trivial MAWs in
\[
O(|MAW(S)|)
\]
time using
\[
O(e)
\]
space, where
\[
e=\min\{er(S),el(S)\},
\]
and \(e<2n\) for any string of length \(n\) [2402.18090]. The paper excludes trivial length-1 absent characters from \(MAW(S)\), so for the fully general SAS problem one must separately check whether some alphabet symbol is absent from \(S\); otherwise the shortest MAW among the non-trivial outputs is the SAS. This separates the combinatorial core of SAS from the trivial alphabet-missing case.

A common misconception is to conflate absent **substrings** with absent **subsequences**. The 2025 paper on shortest absent subsequences proves that every shortest absent subsequence has length \(\iota(w)+1\), where \(\iota(w)\) is the universality index, and gives linear-preprocessing enumeration algorithms with output-linear or constant delay [2504.21471]. Those results concern scattered subsequences rather than contiguous factors. They belong to the same missing-pattern landscape, but their arch-factorization and canonical-embedding machinery is subsequence-specific rather than a reformulation of SAS.

In this sense, SAS occupies a precise place within stringology: it is simultaneously a classical suffix-tree problem, a minimum-length layer of the MAW family, an internal substring-query target, and—under packed inputs—a problem whose optimal formulation depends on representation-sensitive complexity rather than on linear-time folklore alone.

Source: https://www.emergentmind.com/topics/shortest-absent-substring-sas