Abstract 1 Introduction 2 Preliminaries 3 Computing a Shortest Unique Substring 4 Computing a Shortest Absent Substring References

Faster Algorithms for Shortest Unique or Absent Substrings

Panagiotis Charalampopoulos ORCID King’s College London, UK    Manal Mohamed ORCID King’s College London, UK    Solon P. Pissis ORCID The Cyprus Institute, Nicosia, Cyprus
CWI, Amsterdam, The Netherlands
Vrije Universiteit Amsterdam, The Netherlands
   Hilde Verbeek ORCID CWI, Amsterdam, The Netherlands    Wiktor Zuba ORCID University of Warsaw, Poland
Abstract

We revisit two well-known algorithmic problems on strings: computing a shortest unique substring (SUS) and a shortest absent substring (SAS) in a string S of length n. Both problems admit folklore 𝒪(n)-time solutions using the suffix tree of S. However, for small alphabets, this complexity is not necessarily optimal in the word RAM model, where a string of length n over alphabet [0,σ) can be stored in 𝒪(nlogσ/logn) space and read in 𝒪(nlogσ/logn) time.

We present an 𝒪(nlogσ/logn)-time algorithm for computing a SUS in S. This algorithm decomposes the problem according to the length and the period of the sought substring and uses several tools and techniques, such as synchronizing sets, the analysis of runs, and wavelet trees, to reduce the computation of a SUS to a simple geometric problem. Further, we adapt this algorithm and combine it with an efficient construction of de Bruijn sequences in order to obtain an 𝒪(nlogσ/logn)-time algorithm for computing a SAS in S.

Keywords and phrases:
string algorithms, unique substrings, absent substrings, absent words
Funding:
Hilde Verbeek: Supported by a Constance van Eeden Fellowship.
Copyright and License:
[Uncaptioned image] © Panagiotis Charalampopoulos, Manal Mohamed, Solon P. Pissis, Hilde Verbeek, and Wiktor Zuba; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Pattern matching
Related Version:
Full Version: https://arxiv.org/abs/2605.04826 [10]
Editor:
Pierre Fraigniaud

1 Introduction

Given a string S over an alphabet Σ, a string P is called unique in S if it occurs exactly once in S as a substring. A unique substring P of S is called a shortest unique substring (SUS) of S if there is no shorter string that is unique in S. Similarly, a string P over Σ is said to be absent from S if it does not occur in S as a substring. A string P that is absent from S is called a shortest absent substring (SAS) of S if no shorter string that is absent from S exists. For example, for string S=gcattgcgtaggt over the alphabet Σ={a,c,g,t}, we have that ag is a SUS of S and aa is a SAS of S.

Shortest unique substrings (SUSs) and shortest absent substrings (SASs) have a wide range of applications in bioinformatics, information retrieval, and data compression. In bioinformatics, SUSs are employed in alignment-free sequence comparison methods [22], whereas in information retrieval they are used to extract minimal text snippets from a document collection containing a query term [31]. Note that the notion of SUS used in [31] is position-dependent: for a given position in the input string, one seeks a SUS covering that position. In contrast, in this work we consider the global variant of the problem, where the goal is to compute a shortest substring that is unique in the entire string. SASs are likewise of significant importance in bioinformatics and data compression. They provide highly specific genomic signatures for pathogens such as SARS-CoV-2 [32], thereby facilitating the development of rapid diagnostic assays and targeted therapeutics [34]. Moreover, SASs are utilized in alignment-free sequence comparison methods [8] and constitute the foundational concept of compression schemes based on antidictionaries [13].

It is a classical exercise to compute a SUS or a SAS of a string S of length n in 𝒪(n) time using the suffix tree of S [37]. In particular, all SUSs and SASs are naturally encoded in the suffix tree of S; see Figure 1 for an illustration.

Figure 1: A schematic illustration of two suffix trees. Left, the root-to-v path-label, appended with letter a, is a unique substring that occurs as a prefix of the suffix represented by the leaf . Right, the root-to-v path-label, appended with letter g{a,c,t}, yields an absent substring.

Here, we consider the unit-cost word RAM model of computation with word size w=Θ(logn) for inputs of size n, and a standard instruction set including arithmetic operations, bitwise Boolean operations, and shifts. We measure the space complexity of our algorithms in terms of the number of machine words used. A packed representation of a string S over an integer alphabet Σ=[0,σ) stores Θ(logσn) letters per machine word (possibly apart from the last one), thus representing S in 𝒪(1+|S|/logσn) machine words. A string given in this representation is referred to as a packed string.

A large body of work exploits bit-level parallelism in the word RAM model to accelerate classical string processing tasks when the input consists of packed strings. In particular, the problems for which speed-ups have been obtained include pattern matching [1, 3, 4, 5, 7, 20, 21, 30], text indexing [6, 18, 36], computing palindromes [12], constructing longest common extension data structures [25], computing a longest common substring [9], constructing the BWT [25], computing Lempel-Ziv (LZ77) factorizations [16, 27], counting squares and locating runs [11], computing Lyndon arrays [2], computing covers [33], and constructing compressed suffix trees and compressed suffix arrays [26].

In this paper, we ask the following question for a string of length n:

Can a SUS (or a SAS) be computed in o(n) time in the packed setting?

Our results.

We answer this question in the affirmative, improving upon the folklore linear-time solutions for computing a single SUS or SAS in the packed setting.

Theorem 1 (SUS).

Given a packed string S of length n over an integer alphabet [0,σ), a shortest unique substring of S can be computed in 𝒪(nlogσ/logn) time.

Theorem 2 (SAS).

Given a packed string S of length n over an integer alphabet [0,σ), a shortest absent substring of S can be computed in 𝒪(nlogσ/logn) time.

Our techniques and paper organization.

We obtain Theorem 1 by decomposing the problem based on the length and the period of the sought substring of S. For short substrings, we employ tabulation. For medium-length aperiodic substrings, we modify an existing technique for longest common substrings [9] that is based on an efficient construction of wavelet trees [29]. For long aperiodic substrings, we combine sampling via string synchronizing sets [17, 25] with a heavy-light decomposition [35] of two compacted tries T and TR. Then, using pairs of heavy paths, we reduce the search to a 2D geometric problem that, as we show, underlies the computation of SUSs. For periodic substrings, we exploit the runs in S [23]: we group them by their Lyndon roots and sparse-Lyndon roots [11] and use this grouping to reduce the search to another instance of said geometric problem. See Section 3.

We obtain Theorem 2 using the same framework, augmented with a new efficient construction of de Bruijn sequences [14] in packed representation. See Section 4.

We start in Section 2 with the necessary preliminaries. Any materials omitted due to space constraints are provided in the full version [10].

Other related work.

Kempa and Kociumaka [28] studied the hardness hierarchy for problems whose fastest known word-RAM algorithms run in 𝒪(nlogn) time on inputs of Θ(n) machine words. This class includes string processing problems such as constructing the BWT [25], computing a longest common substring [9], and computing LZ77 factorizations [27]. For these problems, they showed that the known 𝒪(n/logn)-time algorithms for binary strings – equivalently, 𝒪(nlogn)-time algorithms when the input size is measured in machine words – are conditionally optimal, with conditional lower bounds established via non-trivial reductions to a variant of dictionary matching. Computing a SUS (Theorem 1) or a SAS (Theorem 2) for binary strings shares the same time complexity. It remains an interesting open problem whether one can improve upon our algorithms or prove that they are conditionally optimal. Let us note that proving a conditional lower bound for our problem using the framework of Kempa and Kociumaka [28] seems challenging. The reductions in said work highlight as the underlying hardness in the studied problems the task of looking for an occurrence of some (sub)string P in a string S (e.g., as in the longest common substring problem). The problems we study here are of a different flavor: in SUS we look for substrings that do not occur elsewhere in S while in SAS we look for strings that do not occur at all in S.

2 Preliminaries

Strings.

An alphabet Σ is a finite set of elements called letters. A string S=S[0]S[1]S[n1] of length |S|=n is a sequence of n letters from Σ. We refer to each i[0,n) as a position of S. We consider throughout an integer alphabet Σ=[0,σ) with σ=n𝒪(1). A string P is a substring of a string S if we have P=S[i]S[i+|P|1] for some position i of S. In this case, we say that P occurs at position i of S. Such an occurrence is called a fragment of S; we denote it by either S[i..i+|P|) or S[i..i+|P|1]. The set of the starting positions of the occurrences of a string P in S is denoted by Occ(P,S). A prefix of S is a fragment of the form S[0..j), and a suffix of S is a fragment of the form S[i..n). A substring P of S is called proper if PS. The reverse of string S, which we denote by SR, is defined as SR=S[n1]S[n2]S[0]. The concatenation of two strings S and S is denoted by SS and the concatenation of k copies of a string S is denoted by Sk.

Definition 3 (Period).

An integer p>0 is a period of a string P if P[i]=P[i+p], for all i[0,|P|p). The smallest period of P is called the period of P and is denoted by per(P). A string P is called periodic if per(P)|P|/2 and aperiodic otherwise.

Example 4.

For string P=abaaabaaabaaaba, we have per(P)=4. Note that 8 is also a period of P. Since per(P)=4|P|/2=15/2, P is periodic.

Definition 5 (Run).

A fragment F=S[i..j] of a string S is called a run of S if per(F)|F|/2, and extending F either to the left or to the right (if possible) would result in an increase of its period, that is, S[i1]S[i1+per(F)] (or i=0) and S[j+1]S[j+1per(F)] (or j=|S|1).

Definition 6 (Lyndon Root).

The Lyndon root of a run F, denoted by Lroot(F), is defined as the lexicographically smallest rotation of the prefix F[0..per(F)) of F.

Definition 7 (Lyndon Representation).

The Lyndon representation of a run F is a quadruple Lrepr(F)=(λ,e,α,β) such that:

  • λ=Lroot(F), and

  • F=PλeT, where P is a (possibly empty) suffix of λ with |P|=α<|λ|, and T is a (possibly empty) prefix of λ with |T|=β<|λ|.

Example 8.

Let S=abaaabaaabaaabab. The underlined fragment F=S[0..14]=abaaabaaabaaaba is a run with per(F)=4|F|/2=15/2. Observe that extending F to the right yields the fragment S[0..15]=S, whose period is 14; hence extending F increases its period. Moreover, we have Lroot(F)=aaab and Lrepr(F)=(aaab,3,2,1).

Definition 9 (τ-Run).

A run R of a string S is called a τ-run, for an integer τ>0, if |R|3τ1 and per(R)13τ.

Lemma 10 (Lemma 2.8 [9]).

Let S be a string of length n over an integer alphabet [0,σ), with σ=n𝒪(1), and let τ>0 be an integer. Then S contains 𝒪(n/τ) τ-runs. Moreover, if τ14logσn, all τ-runs in S can be computed and grouped by their Lyndon roots in 𝒪(n/τ) time. Within the same time bound, for each τ-run, we can compute the two leftmost occurrences of its Lyndon root.

Definition 11 (Shortest Unique Substring (SUS)).

A string P is a unique substring of a string S if and only if |Occ(P,S)|=1. A unique substring P of S is called a shortest unique substring of S if there is no string P with |P|<|P| that is a unique substring of S.

Definition 12 (Shortest Absent Substring (SAS)).

A string P is absent from a string S if and only if |Occ(P,S)|=0. An absent string P of S is called a shortest absent substring of S, if there is no string P with |P|<|P| that is absent from S.

String synchronizing sets.

We next define a powerful sampling mechanism.

Definition 13 (String Synchronizing Set [25]).

For a string S of length n and a positive integer τ[1,n2], a set 𝐒𝐲𝐧𝐜[0,n2τ] is a τ-synchronizing set of S if it satisfies:

  1. 1.

    Consistency: For i,j[0,n2τ], if S[i..i+2τ)=S[j..j+2τ), then i𝐒𝐲𝐧𝐜 if and only if j𝐒𝐲𝐧𝐜.

  2. 2.

    Density: For i[0,n3τ+1], 𝐒𝐲𝐧𝐜[i,i+τ)= if and only if per(S[i..i+3τ1))13τ.

Theorem 14 ([17]).

A string S[0,σ)n can be preprocessed in 𝒪(nlogσn) time so that, given τ[1,n/2], a τ-synchronizing set 𝐒𝐲𝐧𝐜 of S of size |𝐒𝐲𝐧𝐜|<70nτ can be constructed in 𝒪(n/τ) time.

Problem definitions.

We now formally define the problems in scope.

Shortest Unique Substring
Input: A packed string S of length n over an integer alphabet Σ=[0,σ).

Output: i,j0 such that P=S[i..j] is a shortest unique substring of S.

Shortest Absent Substring
Input: A packed string S of length n over an integer alphabet Σ=[0,σ).

Output: i,j0 and cΣ such that P=S[i..j]c is a shortest absent substring of S.

The folklore 𝒪(n)-time solutions to the above problems are sketched in [10]. In [10], we also show that any Shortest Unique Substring instance of length n over alphabet [0,σ) can be reduced in 𝒪(nlogσn) time to an instance of length 𝒪(nlogσ) over a binary alphabet. This implies that the binary alphabet constitutes a hardest case for computing a SUS. In particular, any algorithm designed for the binary case can be applied to general alphabets via this reduction, without any increase in the asymptotic running time.

In what follows, we assume that all considered strings are given in packed representation. When it is clear from the context, we may omit the term packed.

3 Computing a Shortest Unique Substring

We decompose the problem into four cases based on the length and the period p of a SUS:

  1. 1.

    Short case: 15logσn (see [10]);

  2. 2.

    Medium aperiodic case: (15logσn,2logn) and p>145logσn (see [10]);

  3. 3.

    Long aperiodic case: log4n and p>19log4n (see Section 3.2);

  4. 4.

    Periodic case: 3τ and p13τ, for τ=115logσn or τ=13log4n (see Section 3.3). Note that when τ=0, this case is obsolete because the period of any string is positive.

We defer the proofs for the short (see Lemma 15) and medium aperiodic (see Corollary 16) cases to the full version [10]: the former case is standard, and for the latter one we draw heavily from previous work [9]. For those cases, we assume familiarity with suffix trees and wavelet trees; a formal exposition of these is also given in [10].

Lemma 15 ([10]).

Given an instance of Shortest Unique Substring, in 𝒪(n/logσn) time, we can either compute a SUS of S of length at most :=15logσn if one exists, or conclude that no SUS of length at most exists.

Corollary 16 ([10]).

Given an instance of Shortest Unique Substring, we can compute a SUS P of S in 𝒪(nlogσ/logn) time if it has length |P|[15logσn,2logn] and period p>145logσn.

3.1 SUS as a Skyline Problem

In this section, we introduce and solve a simple geometric problem that serves as a subroutine for computing a SUS in both the long aperiodic and the periodic cases.

Definition 17 (Domination in 02).

Let p1=(x1,y1) and p2=(x2,y2) be two points in 02. We say that p1 is dominated by p2 if x1x2 and y1y2.

Definition 18 (Shadow).

Let P be a multiset of points in 02. The shadow of a point pP is the set of points in 02 that are dominated by p but not dominated by any pP{p}.

Definition 19 (Skyline).

Let P be a multiset of points in 02. The primary skyline of P is the union of the shadows of all points in P.

Example 20.

The primary skyline of {(7,3),(7,3)} is the empty set.

In the following, we formalize the Minimum Skyline Point problem, explain its relevance to finding a SUS of S, and present a linear-time solution; see Figure 2 for an example.

Minimum Skyline Point
Input: A multiset P of points in 02.

Output: A point (x,y)02 that lies in the primary skyline of P and minimizes x+y, if one exists.

Figure 2: A set P (left) and its primary skyline (right). The union of the shadows of the points in P consists of all points within the shaded polygon but outside its heavily shaded part – the points in the heavily shaded part are dominated by multiple points from P. For this instance of Minimum Skyline Point, the output would be point (2,3), shown with a rhombus.
Lemma 21.

Any instance of Minimum Skyline Point can be solved in 𝒪(|P|) time if the points in P are given as a list sorted with respect to one of the two coordinates.

Proof.

We first establish two claims.

Claim 22.

Suppose that the primary skyline is nonempty and let (x,y) be a point in the primary skyline with minimal sum of coordinates. Then, either x=0 or there exists a point (x,y)P with x=x1.

Proof.

Assume, toward a contradiction, that the claim is false; that is, that we have x>0 and there is no point (x,y)P with x=x1. Let p=(x,y). By the definition of the primary skyline, p must be dominated by exactly one point in P. Now consider the point pleft=(x1,y), which, due to the minimality of the coordinate-wise sum of p, must be dominated by at least two points in P. Therefore, there exists a point pP that dominates pleft and does not dominate p. Let p=(x,y). Since p does not dominate p, we must have either x<x or y<y. We obtain a contradiction in each case:

  • If x<x, then by our assumption that no point (x,y)P has x=x1, we must have xx2. Hence, x<x1, and thus p does not dominate pleft, a contradiction.

  • If y<y, then p clearly does not dominate pleft, a contradiction.

Claim 23.

Suppose that the primary skyline is nonempty and let (x,y) be a point in the primary skyline with minimal sum of coordinates. Let P={(x,y)Pxx} and let punique be the unique point of P that dominates (x,y). If |P|=1, we have y=0. Else, we have y=y+1, where y is the maximum y-coordinate of a point in P{punique}.

Proof.

By definition, p:=(x,y) is dominated by exactly one point, namely punique. Since points are only dominated by points weakly to their right, we have that punique must be in P. We distinguish between two cases:

Case 1: |𝑷|=𝟏.

We have P={punique}. If y>0, then the point pdown=(x,y1) is in 02 and the only point of P that dominates it is punique. Thus, pdown lies in the primary skyline, but its coordinate sum x+y1 is smaller than that of p, contradicting the minimality of p. Hence, y=0.

Case 2: |𝑷|𝟐.

Let Pother=P{punique}, and let y be the maximum y-coordinate of a point in Pother. Since p is dominated uniquely by punique, every point (x′′,y′′)Pother satisfies y′′<y. Hence, y<y. Conversely, since punique dominates p, its y-coordinate is at least y. Therefore, the point (x,y) is dominated by exactly one point in P if and only if y<y. By the minimality of p, we have y=y+1.

Algorithm.

We assume, without loss of generality, that the points in P are sorted by x-coordinate in non-decreasing order. We scan P from right to left, while maintaining ymax and y, the two largest y-coordinates encountered among processed points (where ymaxy). We initialize ymax and y to 1, indicating that no processed point has contributed a valid y-coordinate yet.

We iterate through P by grouping points with the same x-coordinate. Let xi denote the current x-coordinate of the group currently being processed, and let Pcurr={(x,y)Px=xi} be the set of points at this coordinate. Before processing the points in Pcurr, we evaluate the candidate x-coordinate x=xi+1. Because we have scanned from right to left, all points (x,y)P such that xx have already been processed. Let P denote this set of previously processed points. We determine the corresponding y following Claim 23:

  • If |P|=1, we set y=0.

  • If |P|2 and ymax>y, we set y=y+1.

  • Otherwise (if |P|=0 or ymax=y), the primary skyline does not intersect the set {(x,y)y0}, so we skip this candidate.

After evaluating y, we update ymax and y using the y-values in Pcurr so that they remain the two largest y-coordinates among all processed points.

Finally, after all points in P have been processed, we perform a last check for the candidate x=0 using the final values of ymax and y. The algorithm maintains the candidate (x,y) that minimizes x+y and returns it as a witness. Each point of P is processed exactly once using 𝒪(1) simple operations, thus the algorithm runs in 𝒪(|P|) time.

Intuition for application to SUS.

In the long aperiodic case (Section 3.2) and in the periodic case (Section 3.3), we show that a SUS of S can be found by solving several instances of the Minimum Skyline Point problem. The core idea is to transform the SUS problem into a geometric one. Let us consider one such instance. We first identify a set 𝒮 of carefully-selected substrings of S, each anchored around a common fragment F=S[i..j]. Each substring U𝒮 is then represented by an integer point (x,y), where x and y are the lengths of the extensions of U to the left and the right, respectively, relative to the common fragment F.

Example 24.

Let S=abracadabra, F=S[4..6]=cad, and 𝒮={bracada,cadabra}. The substrings are represented as points by the lengths of their extensions relative to F:
bracada (3,1) (since bra is of length 3 and a is of length 1), and cadabra (0,4) (since the left extension is empty and abra is of length 4).

Since strings in 𝒮 are substrings of S anchored around a common fragment, each point maps to one substring of S. Then, a string U𝒮 is a substring of string V𝒮 if and only if the point representing U is dominated by the point representing V. To find a candidate SUS in 𝒮, we look for a minimal extension anchored around F that is contained within exactly one substring from 𝒮. This is equivalent to solving a Minimum Skyline Point instance: finding an integer point (x,y) that lies in the primary skyline of the points representing 𝒮 that minimizes x+y. The total length of the resulting SUS is then |F|+x+y.

3.2 Long Aperiodic Case

This section addresses the computation of a SUS in the case when log4n and p>19log4n. Let us start with a high-level overview of our solution for this case. We construct a string synchronizing set consisting of anchor positions in S that enable the identification of identical sufficiently long aperiodic patterns. These anchors are then used to construct two tries whose root-to-leaf paths represent occurrences of these patterns. SUSs are found by locating the shortest paths that occur only once. We achieve this by formulating several instances of the Minimum Skyline Point problem based on these tries.

We apply Theorem 14 on S with τ:=13log4n and denote the resulting τ-synchronizing set by 𝐒𝐲𝐧𝐜. The following proposition is crucial: if a sufficiently long, aperiodic pattern occurs twice in the string, then every anchor within one occurrence must have a corresponding anchor at the same relative position in the other occurrence. Therefore, to find a unique pattern, we must locate an anchor whose surrounding fragments – those immediately preceding and succeeding it – do not occur around any other anchor and have minimal total length.

Proposition 25 (follows by Definition 13).

Suppose that a substring X of S with length |X|=m3τ and period per(X)>13τ occurs at distinct positions i and j in S. Then for all q[0,m2τ], we have i+q𝐒𝐲𝐧𝐜 if and only if j+q𝐒𝐲𝐧𝐜.

We construct two tries T and TR. For every anchor position i𝐒𝐲𝐧𝐜, we insert S[i..n) into T and S[0..i)R into TR. In both tries, the leaves are labeled with their corresponding anchor positions. For efficiency, we implement them as compacted tries, where nodes with a single child are suppressed and are called implicit; all other nodes (i.e., the root, branching nodes, and leaves) are maintained and are called explicit. For any explicit node v, let L(v) denote the set of leaf labels in the subtree rooted at v, let str(v) denote the concatenation of the edge labels from the root to v, and let sd(v) denote the string depth of v. Note that these definitions extend naturally to implicit nodes. If an occurrence of a pattern P contains an anchor i𝐒𝐲𝐧𝐜, then there exist nodes u in TR and v in T such that P=str(u)Rstr(v) and iL(u)L(v). Moreover, the size |L(u)L(v)| equals the number of occurrences of P, provided that P is sufficiently long and aperiodic. We formalize our task as follows; for convenience, for the remainder of this section, we assume that the parent of the root node is itself.

Two Trees SUS
Input: Two rooted trees T1 and T2, each with size at most N and with leaves uniquely labeled from [0,N), a weight function w with range 0 where w(u)>w(v) for every strict ancestor v of every node u, and an integer k.

Output: A pair (u,v) of nodes u in T1 and v in T2 minimizing w(parent(u))+max(w(parent(v)),k1), subject to |L(u)L(v)|=1 and w(v)k (if they exist).

Lemma 26.

Consider a Shortest Unique Substring instance and let τ:=13log4n. If S has a SUS of length 3τ and period p>13τ, we can reduce its computation in 𝒪(n/logσn) time to an instance of Two Trees SUS with N=𝒪(n/τ) and k=2τ.

Proof.

We begin by constructing a τ-synchronizing set 𝐒𝐲𝐧𝐜 of S. Using this set, we construct two compacted tries T and TR. For every anchor i𝐒𝐲𝐧𝐜, we insert the suffix S[i..n) into T and the reversed prefix S[0..i)R into TR, labeling the corresponding leaves with the anchor i in both tries. We make all implicit nodes in T at string depth k1 explicit. Hence, we have N=𝒪(|𝐒𝐲𝐧𝐜|)=𝒪(n/τ)=𝒪(n/log4n).

Any fragment P in S that contains at least one anchor i𝐒𝐲𝐧𝐜 can be decomposed into P=str(u)Rstr(v), where u is a node in TR and v is a node in T, both of which can be implicit. If P has length at least 3τ and period greater than 13τ, then by the definition of τ-synchronizing sets, all occurrences of P have anchors at the same relative positions. Specifically, any occurrence of P starting at position j must have j+q𝐒𝐲𝐧𝐜 if and only if the original occurrence at position i had an anchor at the same offset (Proposition 25). Thus, if the node pair (u,v) represents the fragment P, the number of occurrences of P is exactly |L(u)L(v)|. To find a SUS, we must find a pair (u,v) of (possibly implicit) nodes such that |L(u)L(v)|=1 (uniqueness), sd(v)2τ (to satisfy the anchor offset property), and sd(u)+sd(v) is minimized.

To do so, we set the weights of nodes in the two trees as follows. In both tries, we set the weight of the root node to 0 and assign to each other node u a weight w(u):=sd(u). We thus create an instance of Two Trees SUS with k=2τ. If the optimal node pair (u,v) satisfies w(parent(u))+w(parent(v))+2<3τ, we conclude that S does not have a SUS of length 3τ and period p>13τ. (Note that since we have made all nodes with string depth k1 explicit, for any node v with w(v)k, v’s parent has weight at least k1, and hence max(w(parent(v)),k1)=w(parent(v)).) Otherwise, we return as a SUS the string str(u)R[0..w(parent(u))]str(v)[0..w(parent(v))] – the indices of the occurrence of this string in S can be inferred from the common leaf label in the subtrees of u and v.

The time complexity depends on the construction of the τ-synchronizing set, which requires 𝒪(n/logσn) time using Theorem 14, and the construction of the tries. For the tries, we first construct an LCE data structure over S in 𝒪(n/logσn) time [25] supporting 𝒪(1)-time LCP queries. We sort the N suffixes of S in 𝒪(NlogN) time using merge sort, performing each comparison with an LCP query and a letter comparison. Given the sorted list of suffixes and the LCE data structure, the tries can then be constructed in 𝒪(N) time [24]. The total time for constructing the tries is 𝒪(n/logσn)+𝒪(NlogN)𝒪(n/logσn).

3.2.1 Solving the Two Trees SUS Problem

We solve Two Trees SUS as follows. We first decompose the trees T1 and T2 into heavy paths. For each pair of heavy paths, one from T1 and one from T2, we then construct a Minimum Skyline Point instance, which we solve in linear time using Lemma 21.

Heavy-light decomposition.

We first recall the widely-used heavy-light decomposition [35].

Definition 27 (Heavy-Light Decomposition [35]).

Consider a rooted tree 𝒯. We obtain a heavy-light decomposition of 𝒯 by marking each edge as either heavy or light as follows. For every internal node of 𝒯, the outgoing edge leading to the child with the largest number of descendants is marked as heavy, while all other outgoing edges are marked as light; ties are resolved arbitrarily. A maximal path of heavy edges is a heavy path.

A heavy-light decomposition can be constructed in linear time [35]. The following fact holds for any heavy-light decomposition:

Fact 28 (Lemma 1 [35]).

In a tree with N leaves, any root-to-leaf path intersects at most logN heavy paths in the decomposition.

Furthermore, we can construct a heavy-path tree that encodes the ancestral relations among all heavy paths and leaves. This is done by contracting every heavy edge, such that all remaining edges are light. In this auxiliary structure, each node corresponds to a contracted heavy path or a leaf. By Fact 28, the heavy-path tree has height at most logN, which allows for efficient traversal across the original tree structure.

A reduction using pairs of heavy paths.

We first note that any internal node of a tree belongs to exactly one heavy path in its heavy-light decomposition. We compute the heavy-light decompositions for T1 and T2 and consider every pair of heavy paths h1 from T1 and h2 from T2, provided that they share at least one leaf label.

For a heavy path h, let L(h) denote the set of all leaves descending from the root of h. We define the function dh:L(h)0, where for some leaf L(h), dh() denotes the weight of ’s lowest ancestor within h. Namely, dh() denotes the maximum weight of a node on h that is an ancestor of leaf . With these definitions, we have the following observation:

Observation 29.

Given a heavy path h, a node v on h, and a leaf descending from the root of h, we have that L(v) if and only if w(v)dh().

To solve Two Trees SUS, we show that it suffices to solve a Minimum Skyline Point instance for every pair of heavy paths (h1,h2) sharing at least one leaf label. By Fact 28, each leaf belongs to at most logN sets L(h) per tree. We can thus construct each subset L(h1)L(h2) by enumerating, for each leaf label , all log2N pairs of heavy paths above it.

Lemma 30.

Any instance of Two Trees SUS can be solved in 𝒪(Nlog3N) time.

Proof.

We construct the heavy-light decompositions of T1 and T2 in 𝒪(N) time [35]. This process partitions each tree into a set of disjoint heavy paths.

For every leaf label [0,N) present in both T1 and T2, we identify all pairs of heavy paths (h1,h2) such that h1 lies on the root-to-leaf path in the first tree and h2 lies on the root-to-leaf path in the second tree. Since any root-to-leaf path intersects at most 𝒪(logN) heavy paths (Fact 28), there are 𝒪(log2N) such pairs for each of the N labels. For each pair, we generate a tuple (h1,h2,dh1(),dh2()), where dh1 and dh2 are retrieved from the weights of the light-edge endpoints. All tuples are generated in 𝒪(Nlog2N) time in total and are stored in one list. We sort the list, using the heavy path identifiers (h1,h2) as primary keys and the value dh1() as the secondary key. This ensures that all tuples corresponding to the same pair (h1,h2) appear consecutively, and are then ordered by dh1(). Using merge sort, this step takes 𝒪(Nlog2Nlog(Nlog2N))=𝒪(Nlog3N) time. Let us denote the sublist corresponding to the pair (h1,h2) of heavy paths by (h1,h2).

Claim 31.

Consider an instance of Two Trees SUS, in which the output nodes are restricted to a given pair of heavy paths h1 and h2 from T1 and T2. Given the list (h1,h2), we can reduce this instance in 𝒪(g) time to an instance of the Minimum Skyline Point problem over a multiset of points of size 𝒪(g), where g=|(h1,h2)|.

Proof.

Recall that in the definition of Two Trees SUS, the integer k is given as a minimum weight on one of the returned nodes. Let =L(h1)L(h2). Assume that ; otherwise, the instance has no solution. We wish to find nodes uh1 and vh2 minimizing w(parent(u))+max(w(parent(v)),k1) such that |L(u)L(v)|=1 and w(v)k. By Observation 29, this reduces to finding the minimum (x1,x2)02 such that exactly one leaf satisfies dh1()x1 and dh2()x2. This is equivalent to solving a Minimum Skyline Point on the multiset P={(dh1(),dh2())}{(,k1),(,k1)}, thus finding a solution (x,y) with minimal x+y – the extra point that we insert in the multiset twice ensures that if the primary skyline is not empty, then yk. Given (h1,h2), we can construct this instance in 𝒪(g) time. Finally, to obtain a solution to Two Trees SUS, we select the nodes u in h1 and v in h2 satisfying w(parent(u))+1=x and either w(parent(v))+1=y or w(parent(v))+1k=yw(v).

We apply Claim 31 to each pair of heavy paths that share at least one leaf label, and solve each instance of the Minimum Skyline Point problem using Lemma 21 in time linear in the number of points. Since the total number of tuples across all pairs of heavy paths is 𝒪(Nlog2N), the total time required for applications of Claim 31 and Lemma 21 is 𝒪(Nlog2N). We maintain the global minimum value of w(parent(u))+max(w(parent(v)),k1) found across all pairs of heavy paths and return a witness pair of nodes as the final solution.

3.2.2 Wrapping Up

The final complexity of the long aperiodic case is determined by the combination of the reduction to the Two Trees SUS problem and the subsequent application of the heavy path based Minimum Skyline Point algorithm.

Lemma 32.

Given an instance of Shortest Unique Substring, we can compute a SUS of S in 𝒪(n/logσn) time if it has length log4n and period p>19log4n.

Proof.

Using Lemma 26, we reduce the long aperiodic case to an instance of the Two Trees SUS problem. The number of leaf labels (anchors) is N=𝒪(|𝐒𝐲𝐧𝐜|)=𝒪(n/log4n). As established in the reduction, constructing the synchronizing set, the LCE data structure, and the two compacted tries T and TR takes 𝒪(n/logσn) time. We then solve the resulting Two Trees SUS instance using the algorithm from Lemma 30. The time required is 𝒪(Nlog3N) and as N is in 𝒪(n/log4n), we obtain a running time of 𝒪(n/logn). Therefore, both the reduction and the solver fit within the target time bound of 𝒪(n/logσn). The algorithm identifies a pair (u,v) minimizing w(parent(u))+max(w(parent(v)),k1) subject to the uniqueness and length constraints. Since the result of the Two Trees SUS problem provides the minimal unique extension for any pattern overlapping an anchor, the resulting substring is a valid SUS for the long aperiodic case.

3.3 Periodic Case

In this section, we address the SUS computation in highly periodic substrings of S. Specifically, we consider substrings of S of medium length with period at most 145logσn, as well as long substrings of S with period at most 19log4n. These two cases are handled using τ-runs with τ=115logσn and τ=13log4n, respectively.

For the first group of τ-runs (where τ=115logσn), we employ their standard Lyndon representation (Definition 7). These runs can be efficiently computed and grouped by means of Lemma 10. Unfortunately, Lemma 10 is not applicable when τ=13log4n. To deal with this, we utilize the recently introduced sparse-Lyndon representation [11] that allows for efficiently grouping the τ-runs for τ=13log4n according to their Lyndon roots, but representing via their sparse-Lyndon root. We formalize this discussion in Lemma 33.

Lemma 33 (Proposition 36 [11]).

For any string S of length n over an integer alphabet [0,σ), with σ=n𝒪(1), all runs in S can be computed and grouped by equal Lyndon roots in 𝒪(n/logσn) time. For runs with period at most 2118logσn, we compute their standard Lyndon representations, while for runs with larger periods we compute their sparse-Lyndon representations.

To streamline the subsequent analysis, we hereafter slightly abuse terminology: the terms τ-run, Lyndon root, and Lyndon representation will be used uniformly for the two classes of runs considered in this section. In the context of the second class (τ=13log4n), these terms implicitly refer to their sparse-Lyndon counterparts.

This unified terminology is justified by the fact that both representations share analogous properties and can be handled identically within our algorithmic framework. We group all τ-runs by Lyndon root in 𝒪(n/logσn) time using Lemma 33; the only difference is that for some groups, we compute the Lyndon representation of runs, while for others, we compute the sparse-Lyndon representation. For further details and a thorough discussion of sparse-Lyndon representations, we refer the reader to [11].

(a) e<e2 (Case 1).
(b) e=e2 (Case 2).
(c) e=e1 (Case 3).
Figure 3: Cases 13 of Lemma 34, illustrating the potential alignment of a run with exponent e within a run with exponent e. Red alignments are guaranteed to be contained within the longer run; yellow alignments are contained only if the extensions of the runs satisfy specific inequalities.
Lemma 34.

Let F and F be two runs in S with the same Lyndon root λ, where Lrepr(F)=(λ,e,α,β) and Lrepr(F)=(λ,e,α,β). We can determine whether F is a unique substring of F as follows:

  1. 1.

    If e<e2, then F is a substring of F, but it is not unique.

  2. 2.

    If e=e2, then F is a substring of F. It is unique if and only if α>α and β>β.

  3. 3.

    If e=e1, then F is a unique substring of F if and only if either α>α or β>β, but not both. (Note: if both α>α and β>β hold, F is not a substring of F.)

  4. 4.

    If e=e, then F is a unique substring of F if and only if αα and ββ.

  5. 5.

    If e>e, then F is not a substring of F.

Proof.

We analyze each case separately by aligning the occurrences of the Lyndon roots in F and F in all possible ways and comparing their extensions; see Figure 3 for illustrative examples. This allows us to determine if no alignment of F is contained within F (i.e., F is not a substring of F), exactly one alignment is contained (unique substring), or multiple alignments are contained (not unique).

  1. 1.

    If e<e2, we can align the first occurrence of the Lyndon root of F with either the second or third occurrence of the Lyndon root of F. In both cases, both extensions of F coincide with complete occurrences of the Lyndon root of F, meaning that F is contained in both alignments and is therefore not a unique substring.

  2. 2.

    If e=e2, there are three possible alignments of the Lyndon roots. In the second alignment, both extensions of F coincide with complete occurrences of the Lyndon root of F, so F is a substring of F. In the first alignment, the left extensions of the runs are aligned, meaning that F is contained in this alignment unless α>α. Similarly, in the third alignment, the same reasoning applies to the right extensions. Therefore, F is a unique substring of F if and only if α>α and β>β.

  3. 3.

    If e=e1, there are two possible alignments. In the first alignment, the left extensions of the runs are aligned while the right extension of F coincides with a complete occurrence of the Lyndon root of F; thus, F is contained in this alignment if αα. The same reasoning applies symmetrically for the second alignment. Therefore, F is a unique substring of F if and only if either α>α or β>β, but not both.

  4. 4.

    If e=e, there is only one possible alignment of the Lyndon roots. For F to be a substring of F, both extensions of F must be shorter than or equal to those of F; that is, αα and ββ.

  5. 5.

    If e>e, any alignment will result in an extension of F being aligned with a Lyndon root of F; therefore, F cannot possibly be a substring of F.

For the following definitions, let λ be the set of τ-runs in S sharing the same Lyndon root λ. Let r:=|λ|, and let eλmax denote the maximum exponent among all τ-runs in λ.

Definition 35 (Mapping 𝔥).

Let Rλ be a run with Lrepr(R)=(λ,e,α,β). We define the function 𝔥, which maps runs to sets of up to three points as follows:

  • If e<eλmax2, then 𝔥(R)=;

  • If e=eλmax2, then 𝔥(R)={(α,β)};

  • If e=eλmax1, then 𝔥(R)={(r+α,β),(α,r+β)};

  • If e=eλmax, then 𝔥(R)={(2r1,β),(α,2r1),(r+α,r+β)}.

Definition 36 (Mapping 𝔤).

Let p=(x,y) be an integer point in [0,2r1]2. We define the function 𝔤 as a mapping from such points to candidate runs as follows:

  • 𝔤(p) has Lyndon root λ;

  • The left and right extensions of 𝔤(p) are α=xmodr and β=ymodr, respectively;

  • The exponent e of 𝔤(p) is determined by the quadrant: e=eλmax, if (xr and yr); e=eλmax1, if (xr and y<r) or (x<r and yr); e=eλmax2, if (x<r and y<r).

Example 37.

Let λ be a set of runs sharing the Lyndon root λ=ab with period r=|λ|=2. Assume that λ consists of three runs, with a maximum exponent of eλmax=6:

  • Lrepr(R1)=(ab,6,1,1)𝔥(R1)={(3,1),(1,3),(3,3)};

  • Lrepr(R2)=(ab,5,0,1)𝔥(R2)={(2,1),(0,3)};

  • Lrepr(R3)=(ab,4,1,0)𝔥(R3)={(1,0)}.

The geometric domain is [0,3]2, as 2r1=3. Applying the mapping function 𝔥 to all runs in λ generates the point set P={(3,1),(1,3),(3,3),(2,1),(0,3),(1,0)}.

Consider the point (2,2). Since xr and yr (specifically, 22), the mapping 𝔤(2,2) assigns the exponent e=6 and extensions α=2mod2=0 and β=2mod2=0. The mapping 𝔤 thus yields the run: 𝔤(2,2)=(λ,6,0,0). This representation corresponds to the string λ6=(ab)6=abababababab. Note that the point (2,2) lies on the primary skyline of P and is minimal in terms of x+y. This geometric property ensures that the corresponding run 𝔤(2,2) belongs to exactly one periodic alignment among the runs in λ (specifically within R1), making abababababab a valid SUS candidate.

(a) e=eλmax2.
(b) e=eλmax1.
(c) e=eλmax.
Figure 4: The mapping 𝔥 from runs to sets of points in [0,2r1]2. The light shaded part represents the primary skyline, while dark shaded regions indicate areas dominated by multiple points, where no unique substring can exist.
Lemma 38.

Let Rλ be a run with Lrepr(R)=(λ,e,α,β), and let p=(x,y) be a point in the domain [0,2r1]2. Then p is in the primary skyline of 𝔥(R) if and only if 𝔤(p) is a unique substring of R.

Proof.

Let 𝔤(p)=R, where Lrepr(R)=(λ,e,α,β). By the definition of 𝔤, we have α=xmodr and β=ymodr. The quadrant containing p determines the candidate exponent e, while the set of points 𝔥(R) (and thus its primary skyline) is determined by the run exponent e; see Figure 4. We verify the correspondence with the cases in Lemma 34 by distinguishing how e compares to e.

  • Case e=e: The point p can be dominated by exactly one point from 𝔥(R) with relative coordinates (α,β). Hence, p belongs to the primary skyline if and only if it is dominated by this single point, which occurs when αα and ββ. This corresponds exactly to the condition for 𝔤(p) to be a unique substring of R (Lemma 34: Case 4).

  • Case e=e𝟏: In this case, p can be dominated by at most two points from 𝔥(R). Point p is dominated by the first point if αα and by the second if ββ. Thus, p belongs to the primary skyline if it is dominated by exactly one of these points. This requires either αα or ββ but not both. Again, this matches the condition for 𝔤(p) to be a unique substring of R (Lemma 34: Case 3).

  • Case e=e𝟐: This occurs only when e=eλmax and p is in the lower-left quadrant (x,y<r). Here, p is always dominated by the point (r+α,r+β) of 𝔥(R). For p to be in the primary skyline, it must not be dominated by the other two points (2r1,β) and (α,2r1). This lack of dominance occurs if and only if α>α and β>β. This happens exactly when 𝔤(p) is a unique substring of R (Lemma 34: Case 2).

Lemma 39.

Given a set λ of runs sharing the same Lyndon root λ, a SUS among these runs can be found by solving a Minimum Skyline Point instance containing at most 3|λ| points. The corresponding set of (unsorted) points can be constructed in 𝒪(|λ|) time.

Proof.

Let eλmax denote the maximum exponent among all runs in λ. By Lemma 34, we know that any SUS within these runs must have an exponent equal to eλmax2, eλmax1 or eλmax. Such a substring thus corresponds to 𝔤(p) for some point p[0,2r1]2, with r=|λ|.

By Lemma 38, p must lie on the primary skyline of 𝔥(R) for some Rλ. Moreover, p cannot belong to the primary skylines of multiple runs; otherwise, 𝔤(p) would not be unique overall. Hence, p must be dominated by exactly one point among all sets 𝔥(R), which can be identified by solving the Minimum Skyline Point instance on the multiset Rλ𝔥(R). Since |𝔥(R)|3 for every R, this instance has size 𝒪(|λ|). Finally, if the resulting point from this instance is (x,y), it corresponds to a substring of length r(eλmax2)+x+y.

Lemma 40.

Given an instance of Shortest Unique Substring and an integer τ, such that τ=115logσn or τ=13log4n, we can compute a SUS of S in 𝒪(n/logσn) time if it has length 3τ and period p13τ.

Proof.

By Lemma 10 and Lemma 33, all runs in S can be computed and grouped by their Lyndon roots in 𝒪(n/logσn) time. Each τ-run is encoded in 𝒪(1) space. Next, using Lemma 39, we construct Minimum Skyline Point instances for all groups. Since each τ-run generates a constant number of points, the total number of points across all instances is 𝒪(n/τ). These points are computed in 𝒪(n/τ) time as per Lemma 10. To solve all Minimum Skyline Point instances in linear time (Lemma 21), the points for each λ instance must be sorted along one axis. This is achieved by globally sorting all generated points using bucket sort. Because the coordinates x and y for any point in an instance for root λ are bounded by 2|λ|1<2τ, the bucket sort can be performed in 𝒪(n/τ+τ) time. After sorting, the points are regrouped per their Lyndon roots. For either chosen value of τ, we have 𝒪(n/τ+τ)=𝒪(n/logσn). This yields a total running time of 𝒪(n/logσn).

3.4 Putting It All Together

Theorem 1 (SUS). [Restated, see original statement.]

Given a packed string S of length n over an integer alphabet [0,σ), a shortest unique substring of S can be computed in 𝒪(nlogσ/logn) time.

Proof.

We have described algorithms to find SUSs with differing lengths and periods: Lemma 15 handles any length up to 15logσn with any period; Corollary 16 handles lengths in the range [15logσn,2logn] with period greater than 145logσn; and Lemma 32 handles lengths above log4n with period greater than 19log4n. Finally, with parameter values τ:=115logσn and τ:=13log4n, Lemma 40 handles the larger length ranges with smaller periods. We run each of the algorithms and return the globally shortest substring output across all instances. The total running time is 𝒪(nlogσ/logn) which is asymptotically dominated by the complexity of the medium-length aperiodic case (Corollary 16).

4 Computing a Shortest Absent Substring

We begin by defining an auxiliary problem closely related to Shortest Unique Substring.

Shortest Exclusive Substring
Input: Two strings S1 and S2 with n=|S1|+|S2| over an integer alphabet Σ=[0,σ).

Output: A shortest substring of S1 that does not occur in S2 (if one exists).

Similar to the solution for Shortest Unique Substring, we solve the Shortest Exclusive Substring problem by decomposing it into four cases based on the length and the period p of the sought substring of S1, obtaining the following result.

Theorem 41 ([10]).

Any instance of Shortest Exclusive Substring can be solved in 𝒪(nlogσ/logn) time when S1 and S2 are given in packed representation.

The proof of Theorem 41 is deferred to [10]. We next present an efficient construction of de Bruijn sequences in the packed setting, which may be of independent interest.

Definition 42 (De Bruijn Sequence [14]).

A de Bruijn sequence of order k over an alphabet Σ of size σ is a string of length σk+k1 in which every string from Σk occurs exactly once.

Lemma 43.

A packed de Bruijn sequence of order k over the integer alphabet [0,σ) for σ2 can be constructed in 𝒪(σkk)=𝒪(nlogσn) time, where n is the length of the sequence. In particular, we can construct its prefix of length in 𝒪(logσn+1) time.

Proof.

A Lyndon word is a string that is lexicographically strictly smaller than all of its proper suffixes. As noted by Fredricksen and Maiorana [19], the concatenation of all Lyndon words whose length divides k, listed in lexicographical order, forms a de Bruijn sequence. Duval [15] provided an algorithm to generate all Lyndon words of length at most k in lexicographical order, generating each word by modifying the previous one.

We achieve the stated running time in the packed setting, by observing that klogσn, and using 𝒪(1) machine words to iterate over all Lyndon words in [0,σ)k.

In what follows, we describe Duval’s algorithm [15] without proving its correctness; we only explain how it can be performed efficiently in the packed setting. We will return a string S, initialized as 0. We then maintain a length-k string w initialized as 0k and a binary string w whose ith bit is set if and only if w[i]=σ1 (we update w together with w). We repeatedly apply the following steps of the generation loop while w[0]σ1:

  1. 1.

    Locate j=max{i:w[i]σ1}. This is done by finding the rightmost 0 in w in 𝒪(1) time using standard bitwise operations.

  2. 2.

    Replace w[j] with w[j]+1 in 𝒪(1) time.

  3. 3.

    The prefix w[0..j] is now a Lyndon word. If (j+1) divides k, we append w[0..j] to S. This takes 𝒪(1) time as the appended string fits into 𝒪(1) machine words.

  4. 4.

    Replace w with the length-k prefix of (w[0..j]). This can be naively performed using 𝒪(k/(j+1)) operations. Consider a potential function π(w)=|{i:w[i]=σ1}|, noting that Step 2 increases π(w) by at most 1. Conversely, in Step 4, values w[i]=σ1 for i>j are replaced with w[imod(j+1)]. Since w[0]<σ1 (the algorithm terminates when w[0] reaches σ1), Ω(k/(j+1)) copies of σ1 are overwritten by setting w=(w[0..j]). As π(w)0 at all times, the total number of operations we perform in Step 4 is asymptotically upper bounded by the number of times Step 2 is executed, and hence the amortized running time of Step 4 is 𝒪(1).

After the last iteration, we complete the sequence by appending 0k1. Observe that, for each integer there are at most σ Lyndon words of length , and hence at most kσ3σkk Lyndon words of length at most k. This proves that there are 𝒪(σkk) iterations of the loop, and the algorithm takes 𝒪(nlogσn) time (where n=σk+k1 and klogσn) as claimed. To output a length- prefix of this sequence we terminate the algorithm once the length of the output sequence reaches , potentially removing up to k1 excessive letters from the final Lyndon word. Since k/logσn=𝒪(1), the total time complexity is

𝒪(+klogσn+1)=𝒪(logσn+1).

Theorem 2 (SAS). [Restated, see original statement.]

Given a packed string S of length n over an integer alphabet [0,σ), a shortest absent substring of S can be computed in 𝒪(nlogσ/logn) time.

Proof.

Let k:=logσn+1. Since σk>n, the length of any SAS is at most k. We first check for a SAS of length at most k1 by applying Theorem 41 to a packed de Bruijn sequence S1 of order k1 (Lemma 43) and S2:=S. If this yields a substring of length at most k1, we are done. Otherwise, if σk=𝒪(n), we create a full packed de Bruijn sequence of order k and repeat the process to find a SAS of length k. If σk=ω(n), we instead generate a prefix S1 of a de Bruijn sequence of order k of length n+1 in 𝒪(nlogσn) time. S1 contains nk+2 distinct substrings of length k. Since S2 has at most nk+1 such substrings, at least one substring of S1 must be absent from S2. We find this witness of length k using Theorem 41 for S1 and S2. The calls to Theorem 41 dominate the total running time, which is 𝒪(nlogσlogn).

References

  • [1] Ricardo A. Baeza-Yates. Improved string searching. Softw. Pract. Exp., 19(3):257–271, 1989. doi:10.1002/SPE.4380190305.
  • [2] Hideo Bannai and Jonas Ellert. Lyndon arrays in sublinear time. In 31st Annual European Symposium on Algorithms, ESA 2023, volume 274 of LIPIcs, pages 14:1–14:16. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2023. doi:10.4230/LIPIcs.ESA.2023.14.
  • [3] Djamal Belazzougui. Worst case efficient single and multiple string matching in the RAM model. In Combinatorial Algorithms - 21st International Workshop, IWOCA 2010, volume 6460 of Lecture Notes in Computer Science, pages 90–102. Springer, 2010. doi:10.1007/978-3-642-19222-7_10.
  • [4] Oren Ben-Kiki, Philip Bille, Dany Breslauer, Leszek Gasieniec, Roberto Grossi, and Oren Weimann. Towards optimal packed string matching. Theoretical Computer Science, 525:111–129, 2014. doi:10.1016/j.tcs.2013.06.013.
  • [5] Philip Bille. Fast searching in packed strings. Journal of Discrete Algorithms, 9(1):49–56, 2011. doi:10.1016/j.jda.2010.09.003.
  • [6] Philip Bille, Inge Li Gørtz, and Frederik Rye Skjoldjensen. Deterministic indexing for packed strings. In 28th Annual Symposium on Combinatorial Pattern Matching, CPM 2017, volume 78 of LIPIcs, pages 6:1–6:11. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2017. doi:10.4230/LIPIcs.CPM.2017.6.
  • [7] Dany Breslauer, Leszek Gasieniec, and Roberto Grossi. Constant-time word-size string matching. In Combinatorial Pattern Matching - 23rd Annual Symposium, CPM 2012, Proceedings, volume 7354 of Lecture Notes in Computer Science, pages 83–96. Springer, 2012. doi:10.1007/978-3-642-31265-6_7.
  • [8] Panagiotis Charalampopoulos, Maxime Crochemore, Gabriele Fici, Robert Mercas, and Solon P. Pissis. Alignment-free sequence comparison using absent words. Inf. Comput., 262:57–68, 2018. doi:10.1016/J.IC.2018.06.002.
  • [9] Panagiotis Charalampopoulos, Tomasz Kociumaka, Jakub Radoszewski, and Solon P. Pissis. Faster algorithms for longest common substring. ACM Trans. Algorithms, 2025. doi:10.1145/3774754.
  • [10] Panagiotis Charalampopoulos, Manal Mohamed, Solon P. Pissis, Hilde Verbeek, and Wiktor Zuba. Faster algorithms for unique or absent substrings. CoRR, 2026. doi:10.48550/arXiv.2605.04826.
  • [11] Panagiotis Charalampopoulos, Manal Mohamed, Jakub Radoszewski, Wojciech Rytter, Tomasz Walen, and Wiktor Zuba. Counting distinct square substrings in sublinear time. In 50th International Symposium on Mathematical Foundations of Computer Science, MFCS 2025, volume 345 of LIPIcs, pages 36:1–36:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. doi:10.4230/LIPIcs.MFCS.2025.36.
  • [12] Panagiotis Charalampopoulos, Solon P. Pissis, and Jakub Radoszewski. Longest palindromic substring in sublinear time. In 33rd Annual Symposium on Combinatorial Pattern Matching, CPM 2022, volume 223 of LIPIcs, pages 20:1–20:9. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.CPM.2022.20.
  • [13] Maxime Crochemore, Filippo Mignosi, Antonio Restivo, and Sergio Salemi. Data compression using antidictionaries. Proc. IEEE, 88(11):1756–1768, 2000. doi:10.1109/5.892711.
  • [14] Nicolaas Govert de Bruijn. A combinatorial problem. Proc. Koninklijke Nederlandse Akademie V. Wetenschappen, 49:758–764, 1946. URL: http://resolver.tudelft.nl/uuid:f9a56551-402a-4428-98e6-1469e38e64c1.
  • [15] Jean-Pierre Duval. Génération d’une section des classes de conjugaison et arbre des mots de lyndon de longueur bornée. Theor. Comput. Sci., 60:255–283, 1988. doi:10.1016/0304-3975(88)90113-2.
  • [16] Jonas Ellert. Sublinear time Lempel-Ziv (LZ77) factorization. In String Processing and Information Retrieval - 30th International Symposium, SPIRE 2023, Proceedings, volume 14240 of Lecture Notes in Computer Science, pages 171–187. Springer, 2023. doi:10.1007/978-3-031-43980-3_14.
  • [17] Jonas Ellert and Tomasz Kociumaka. Time-optimal construction of string synchronizing sets. In 43rd International Symposium on Theoretical Aspects of Computer Science, STACS 2026, LIPIcs, pages 36:1–36:22. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2026. doi:10.4230/LIPIcs.STACS.2026.36.
  • [18] Johannes Fischer and Paweł Gawrychowski. Alphabet-dependent string searching with wexponential search trees. In Combinatorial Pattern Matching - 26th Annual Symposium, CPM 2015, Proceedings, volume 9133 of Lecture Notes in Computer Science, pages 160–171. Springer, 2015. doi:10.1007/978-3-319-19929-0_14.
  • [19] Harold Fredricksen and James Maiorana. Necklaces of beads in k colors and k-ary de bruijn sequences. Discret. Math., 23(3):207–210, 1978. doi:10.1016/0012-365X(78)90002-X.
  • [20] Kimmo Fredriksson. Shift-or string matching with super-alphabets. Information Processing Letters, 87(4):201–204, 2003. doi:10.1016/S0020-0190(03)00296-5.
  • [21] Szymon Grabowski and Kimmo Fredriksson. Bit-parallel string matching under hamming distance in o(n[m/w]) worst case time. Inf. Process. Lett., 105(5):182–187, 2008. doi:10.1016/J.IPL.2007.08.021.
  • [22] Bernhard Haubold, Nora Pierstorff, Friedrich Möller, and Thomas Wiehe. Genome comparison without alignment using shortest unique substrings. BMC Bioinform., 6:123, 2005. doi:10.1186/1471-2105-6-123.
  • [23] Costas S. Iliopoulos, Dennis W. G. Moore, and William F. Smyth. A characterization of the squares in a fibonacci string. Theor. Comput. Sci., 172(1-2):281–291, 1997. doi:10.1016/S0304-3975(96)00141-7.
  • [24] Toru Kasai, Gunho Lee, Hiroki Arimura, Setsuo Arikawa, and Kunsoo Park. Linear-time longest-common-prefix computation in suffix arrays and its applications. In Combinatorial Pattern Matching, 12th Annual Symposium, CPM 2001, volume 2089 of Lecture Notes in Computer Science, pages 181–192. Springer, 2001. doi:10.1007/3-540-48194-X_17.
  • [25] Dominik Kempa and Tomasz Kociumaka. String synchronizing sets: sublinear-time BWT construction and optimal LCE data structure. In Proceedings of the 51st Annual ACM SIGACT Symposium on Theory of Computing, STOC 2019, pages 756–767. ACM, 2019. doi:10.1145/3313276.3316368.
  • [26] Dominik Kempa and Tomasz Kociumaka. Breaking the O(n)-barrier in the construction of compressed suffix arrays and suffix trees. In Proceedings of the 2023 ACM-SIAM Symposium on Discrete Algorithms, SODA 2023, pages 5122–5202. SIAM, 2023. doi:10.1137/1.9781611977554.CH187.
  • [27] Dominik Kempa and Tomasz Kociumaka. Lempel-Ziv (LZ77) factorization in sublinear time. In 65th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2024, pages 2045–2055. IEEE, 2024. doi:10.1109/FOCS61266.2024.00122.
  • [28] Dominik Kempa and Tomasz Kociumaka. On the hardness hierarchy for the o(nlog n) complexity in the word RAM. In Proceedings of the 57th Annual ACM Symposium on Theory of Computing, STOC 2025, pages 290–300. ACM, 2025. doi:10.1145/3717823.3718291.
  • [29] J. Ian Munro, Yakov Nekrich, and Jeffrey Scott Vitter. Fast construction of wavelet trees. Theor. Comput. Sci., 638:91–97, 2016. doi:10.1016/j.tcs.2015.11.011.
  • [30] Gonzalo Navarro and Mathieu Raffinot. A bit-parallel approach to suffix automata: Fast extended string matching. In Combinatorial Pattern Matching, 9th Annual Symposium, CPM 98, Proceedings, volume 1448 of Lecture Notes in Computer Science, pages 14–33. Springer, 1998. doi:10.1007/BFB0030778.
  • [31] Jian Pei, Wush Chi-Hsuan Wu, and Mi-Yen Yeh. On shortest unique substring queries. In 29th IEEE International Conference on Data Engineering, ICDE 2013, pages 937–948. IEEE Computer Society, 2013. doi:10.1109/ICDE.2013.6544887.
  • [32] Diogo Pratas and Jorge Miguel Silva. Persistent minimal sequences of SARS-CoV-2. Bioinform., 36(21):5129–5132, 2021. doi:10.1093/BIOINFORMATICS/BTAA686.
  • [33] Jakub Radoszewski and Wiktor Zuba. Computing string covers in sublinear time. In String Processing and Information Retrieval - 31st International Symposium, SPIRE 2024, Proceedings, volume 14899 of Lecture Notes in Computer Science, pages 272–288. Springer, 2024. doi:10.1007/978-3-031-72200-4_21.
  • [34] Raquel M. Silva, Diogo Pratas, Luísa Castro, Armando J. Pinho, and Paulo Jorge S. G. Ferreira. Three minimal sequences found in ebola virus genomes and absent from human DNA. Bioinform., 31(15):2421–2425, 2015. doi:10.1093/BIOINFORMATICS/BTV189.
  • [35] Daniel Dominic Sleator and Robert Endre Tarjan. A data structure for dynamic trees. J. Comput. Syst. Sci., 26(3):362–391, 1983. doi:10.1016/0022-0000(83)90006-5.
  • [36] Takuya Takagi, Shunsuke Inenaga, Kunihiko Sadakane, and Hiroki Arimura. Packed compact tries: A fast and efficient data structure for online string processing. IEICE Trans. Fundam. Electron. Commun. Comput. Sci., 100-A(9):1785–1793, 2017. doi:10.1587/TRANSFUN.E100.A.1785.
  • [37] Peter Weiner. Linear pattern matching algorithms. In 14th Annual Symposium on Switching and Automata Theory, pages 1–11. IEEE Computer Society, 1973. doi:10.1109/SWAT.1973.13.