---
title: 'Shortest Unique Substring (SUS): Theory and Algorithms'
url: https://www.emergentmind.com/topics/shortest-unique-substring-sus
type: topic
---

# Shortest Unique Substring (SUS): Theory and Algorithms

In string algorithms, a shortest unique substring (SUS) is a unique substring that is minimum-length subject to a query constraint, usually the requirement to cover a position or interval. For a string \(S\) and interval \([s,t]\), a substring \(S[i..j]\) is a SUS for \([s,t]\) if it occurs exactly once in \(S\), \([s,t] \subseteq [i,j]\), and every shorter substring containing \([s,t]\) is repeating. The literature also studies a global variant that asks for any globally shortest substring that occurs exactly once in the entire string. Across these formulations, SUS is tightly connected to minimal unique substrings (MUSs), which underlie many optimal query algorithms, succinct indexes, and dynamic maintenance results [1609.07220][2605.04826].

## 1. Definitions and problem formulations

The standard query version is interval-based. A substring \(Q\) of a string \(S\) is a shortest unique substring for interval \([s,t]\) if \(Q\) occurs exactly once in \(S\), its occurrence contains \([s,t]\), and every substring of \(S\) that contains \([s,t]\) and is shorter than \(Q\) occurs at least twice. When \(s=t\), the problem is the point SUS problem; when \(s \le t\), it is the interval SUS problem [1609.07220].

A common single-position formulation fixes a location \(k \in \{1,\dots,n\}\) and asks for a shortest substring \(S[i..j]\) such that \(i \le k \le j\) and \(S[i..j]\) is unique in the entire string. In this model, an SUS always exists because the whole string is unique if needed, and a location can have multiple SUSes. For example, in \(S=\texttt{abcbb}\), location \(2\) has two SUSes: \(\texttt{ab}\) and \(\texttt{bc}\) [1312.2738].

The same term is also used for a global optimization problem: find any shortest substring \(P\) of \(S\) with \(|Occ(P,S)|=1\). This version is distinct from query-dependent SUS, because it does not impose a position or interval coverage constraint [2605.04826].

These formulations share the same uniqueness primitive but differ in objective. Query SUS minimizes length among substrings that cover a prescribed query range, whereas global SUS minimizes length over the entire string without a coverage condition. This distinction is central in comparing older suffix-array-based query algorithms with recent packed-word-RAM algorithms for the global problem [1312.2738][2605.04826].

## 2. MUS, LSUS, and the structural basis of SUS

A substring \(u\) of a string \(T\) is a minimal unique substring (MUS) if \(\operatorname{occ}_T(u)=1\) and every proper substring of \(u\) occurs at least twice in \(T\). Equivalently, if \(u=T[s..t]\), then \(u\) is a MUS iff \(T[s..t]\) is unique, \(T[s+1..t]\) is repeating, and \(T[s..t-1]\) is repeating [1909.02804].

MUS and SUS are related but not identical. A MUS is minimal by substring inclusion, whereas a SUS is shortest by length under a query constraint. In particular, not every SUS is necessarily a MUS in the strongest general sense of “the shortest unique substring returned by a SUS query.” The role of MUS is structural: MUSs are heavily utilized for solving the SUS problem, and shortest unique substrings are typically found among MUSs or derived from MUS-related structure [1909.02804].

This relationship is sharpened by the fact that every SUS contains exactly one MUS, and no MUS is nested in another MUS. The non-nesting property yields \(0 < |MUS_T| \le n\), which is a recurring combinatorial invariant in both succinct encodings and output bounds [1905.12854].

A second foundational object is the left-bounded shortest unique substring (LSUS). For each position \(i\), \(\mathit{LSUS}_i\) is the shortest unique substring that starts exactly at \(i\). Using the suffix array \(\mathit{SA}\), inverse suffix array \(\mathit{rank}\), and LCP array, one defines
\[
L_i=\max\{\mathit{LCP}[\mathit{rank}[i]],\ \mathit{LCP}[\mathit{rank}[i]+1]\},
\]
and then
\[
\mathit{LSUS}_i=
\begin{cases}
S[i\ldots i+L_i] & \text{if } i+L_i\le n,\\
\emptyset & \text{otherwise.}
\end{cases}
\]
This gives a direct suffix-array characterization of shortest unique prefixes of suffixes [1312.2738].

The key structural lemma for point SUS is that every \(\mathit{SUS}_k\) is either an \(\mathit{LSUS}\) or a right extension of an \(\mathit{LSUS}\). Moreover, if \(\mathit{SUS}_k\) is obtained by extension, then \(\mathit{SUS}_{k-1}\) ends exactly at position \(k-1\) and \(\mathit{SUS}_k=\mathit{SUS}_{k-1}\cdot S[k]\). This recurrence is the basis of left-to-right optimal algorithms [1312.2738].

## 3. Exact algorithms for reporting SUS answers

The central exact result for point SUS is an optimal \(O(n)\)-time, \(O(n)\)-space algorithm that computes an SUS for every location of a string of length \(n\), substantially improving the earlier \(O(n^2)\) method. The same framework also reports all SUSes covering each location, not just one representative [1312.2738].

The algorithm separates the problem into two layers. First, it computes all LSUSes from suffix-array primitives. Second, it maintains \(\mathit{SLS}_k\), the shortest LSUS covering location \(k\), while sweeping from left to right. The maintained state is a linked list of chunks, each storing \(\texttt{ChunkStart}\), \(\texttt{ChunkEnd}\), \(\texttt{start}\), and \(\texttt{length}\). A monotonicity property over candidate lengths allows chunk merges, and the total merging cost is \(O(n)\), yielding amortized \(O(1)\) update time per position [1312.2738].

Once \(\mathit{SLS}_k\) is known, \(\mathit{SUS}_k\) is chosen between \(\mathit{SLS}_k\) and the one-character extension of \(\mathit{SUS}_{k-1}\), taking the shorter candidate and breaking ties by the leftmost one. This gives a linear-time scan after linear preprocessing of suffix-array and LCP information [1312.2738].

The same paper gives an output-sensitive extension for enumerating all SUSes covering a position. After the leftmost SUS for \(k\) is known, all LSUS-derived candidates of equal minimum length can be reported, together with the one-character extension of \(\mathit{SUS}_{k-1}\) when it ties. The extra cost is proportional to the number of outputs [1312.2738].

A different exact line of work emphasizes memory minimization. An in-place framework computes SUS for every position using two integer arrays \(A\) and \(B\) of length \(n\) in addition to the input string. It organizes the computation into three stages: compute all \(\lsus_i^k\), derive the rightmost shortest LSUS covering each position \(\sls_i^k\), and then obtain the final \(\sus_i^k\). For the exact case \(k=0\), this yields \(O(n)\) total time with \(2n\) memory words plus \(n\) bytes [1512.00378].

## 4. Combinatorial structure and multiplicity of SUS answers

The combinatorics of SUS are unusually rigid. For point queries, let \(\mathcal{PS}_S\) be the set of intervals in \(S\) that correspond to point SUSs over all query positions. Then
\[
|\mathcal{PS}_S| \le (3|S|-1)/2,
\]
and this bound is tight: for any odd \(n \ge 5\), there exists a string \(T\) of length \(n\) such that
\[
|\mathcal{PS}_T| = (3n-1)/2.
\]
Thus the maximum number of distinct point-SUS intervals is strictly less than \(1.5n\) and cannot be improved asymptotically [1609.07220].

The proof combines two inequalities involving the number of MUSs:
\[
|\mathcal{PS}_S| \le 2|S| - |\mathcal{M}_S|
\qquad\text{and}\qquad
|\mathcal{PS}_S| \le |S| + |\mathcal{M}_S| - 1.
\]
Combining them yields the tight \((3|S|-1)/2\) upper bound. The argument exploits the decomposition of point SUSs into three disjoint sets: SUSs that are themselves MUSs, SUSs obtained by extending a MUS to the left, and SUSs obtained by extending a MUS to the right [1609.07220].

An important local consequence is that a position can have at most two point SUSs, and when there are two they have a rigid shape. Specifically, if \(|f^{-1}(u)|=2\), then there exist \(1 \le i < j \le m\) such that
\[
SUS_S(u)=\{[b_i,u], [u,e_j]\}.
\]
One answer is of the form “extend left from a MUS boundary to \(u\),” and the other is of the form “extend right from \(u\) to a MUS boundary” [1609.07220].

For interval queries, the set \(\mathcal{IS}_S\) of non-trivial interval SUSs satisfies
\[
|\mathcal{IS}_S| \le 2|S| - |\mathcal{M}_S|,
\]
and for any \(\varepsilon>0\), there exists a string \(T\) of length \(n\) with
\[
|\mathcal{IS}_T| > (2-\varepsilon)n.
\]
Hence the number of non-trivial interval SUSs is asymptotically below \(2n\), and this upper bound is nearly tight [1609.07220].

These results correct a frequent misconception that SUS answers are either unique or structurally unconstrained. The theory shows the opposite: multiplicity is possible, but tightly bounded and strongly organized by MUS boundaries [1609.07220].

## 5. Succinct indexes, sliding windows, and packed-string algorithms

Space-efficient indexing has led to \(O(n)\)-bit data structures for both interval and point SUS queries. For interval queries, a structure of size
\[
2n + 2m + o(n)\ \text{bits}
\]
answers an interval SUS query in output-sensitive \(O(\mathit{occ})\) time, where \(m=|MUS_T|\). For point queries, a smaller structure of size
\[
\left\lceil (\log_2 3 + 1)n \right\rceil + o(n)\ \text{bits}
\]
answers a point SUS query in the same output-sensitive time. These structures rely on compact representations of MUS boundaries, notably bit vectors \(MB_T\) and \(ME_T\), together with rank/select support and succinct RMQ machinery [1905.12854].

The same work gives space-efficient algorithms for computing MUSs. For each position \(i\), defining
\[
\ell_i=\max\{LCP_T[ISA_T[i]],\, LCP_T[ISA_T[i]+1]\},
\]
one obtains that \(T[i..i+\ell_i-1]\) is the longest repeating substring starting at \(i\), and \(T[i..i+\ell_i]\) is the shortest unique substring starting at \(i\), unless it reaches the end of the text. MUS boundaries can therefore be found by scanning the text while accessing \(ISA_T\) and \(LCP_T\) [1905.12854].

Dynamic and streaming settings are most naturally handled at the MUS level. In a sliding window \(T[i..i+d-1]\), the set of MUSs changes by only \(O(1)\) substrings per slide. More precisely,
\[
|MUS(T[i..j+1]) \triangle MUS(T[i..j])| \le 4
\]
and
\[
-1 \le |MUS(T[i..j+1])| - |MUS(T[i..j])| \le 2,
\]
with symmetric bounds for deleting the leftmost character; both bounds are tight for \(\sigma \ge 3\). This yields an \(O(n\log \sigma)\)-time and \(O(d)\)-space algorithm for maintaining all MUSs in a sliding window of width \(d\). The algorithm maintains a suffix tree for the current window together with three active loci: the primary active point \(pp_{i,j}\) for \(lrs_{i,j}\), the secondary active point \(sp_{i,j}\) for \(sqs_{i,j}\), and the tertiary active point \(tp_{i,j}\) for the longest suffix occurring at least three times [1909.02804].

This MUS maintenance result is directly relevant to SUS because MUSs are the structural atoms behind shortest unique substrings. A plausible implication is that dynamic SUS computation in a sliding-window setting can inherit the same locality of updates [1909.02804].

At the opposite end of the model spectrum, recent work revisits the global SUS problem in the packed word RAM model. While folklore suffix-tree solutions run in \(O(n)\) time, packed inputs over alphabet \([0,\sigma)\) can be read in \(O(n\log \sigma/\log n)\) time, so linear time is not necessarily optimal. An algorithm running in
\[
O\!\left(\frac{n\log \sigma}{\sqrt{\log n}}\right)
\]
computes a global shortest unique substring by decomposing the problem according to substring length and period, and combining synchronizing sets, runs, wavelet trees, heavy-light decomposition, and a 2D skyline geometry reduction [2605.04826].

## 6. Variants, analogues, and terminology

Approximate SUS introduces mismatches into the uniqueness predicate. For a string \(S[1..n]\), a substring is \(k\)-mismatch unique if there is no other substring of the same length starting elsewhere whose Hamming distance is at most \(k\). The \(k\)-mismatch SUS covering position \(p\), denoted \(\sus_p^k\), is then the shortest \(k\)-mismatch unique substring containing \(p\). Using the same three-stage in-place framework as in the exact case, all exact SUSes for every position are computed in \(O(n)\) time, and all approximate \(k\)-mismatch SUSes in \(O(n^2)\) time, regardless of \(k\), while using \(2n\) memory words plus \(n\) bytes [1512.00378].

A closely related but distinct problem is the shortest unique palindromic substring (SUPS). Here the substring must be both unique and palindromic. After \(O(n)\)-time and \(O(n)\)-space preprocessing, all SUPSs for an interval query \([x,y]\) can be answered in \(O(k+1)\) time, where \(k\) is the number of outputs [1608.05550]. Later work sharpened this structure by proving that the number of SUPSs for any query interval is at most \(4\), and that this upper bound is tight, while also giving the first \(O(n)\)-bits data structures answering any interval or point SUPS query in \(O(1)\) time [2204.07327]. SUPS is not ordinary SUS with a trivial extra predicate: the palindrome constraint changes the candidate structure fundamentally.

The literature also contains a terminological divergence in which “SUS” means *smallest* unique substring rather than *shortest* unique substring. In the “SUS-anchor” sampling scheme, a window \(W\) selects the start position of the smallest unique suffix under a character-based order, especially the anti-lexicographic order that minimizes the first character and maximizes the remaining characters. This notion is explicitly distinguished from classical shortest-unique-substring problems. The resulting anchors are forward for any character-based order, can be computed in \(O(n)\) time and \(O(w)\) space for window length \(w\), and for alphabet size \(\sigma=4\) and \(k=1\) the anti-lexicographic SUS-anchor is empirically within \(1\%\) of the density lower bound [2606.01190].

Taken together, these variants show that SUS is less a single problem than a family of uniqueness-minimization problems. The classical point and interval formulations remain centered on MUS/LSUS structure, suffix-array or suffix-tree primitives, and output-sensitive reporting; approximate, palindromic, dynamic, and packed-model variants preserve this core while altering the admissible substring class, the update model, or the computational model [1312.2738][1512.00378][2204.07327].

Source: https://www.emergentmind.com/topics/shortest-unique-substring-sus