Abstract 1 Introduction 2 Preliminaries 3 Upper bound ๐Ÿโข๐’“ of net occurrences and MUSs 4 R-enum revisited 5 An ๐‘ถโข(๐’“)-size data structure for NF-queries 6 Conclusions References

R-Enum Revisited: Speedup and Extension for Context-Sensitive Repeats and Net Frequencies

Kotaro Kimura ORCID Kyushu Institute of Technology, Fukuoka, Japan โ€ƒโ€ƒ Tomohiro I ORCID Kyushu Institute of Technology, Fukuoka, Japan
Abstract

A repeat is a substring that occurs at least twice in a string, and is called a maximal repeat if it cannot be extended outwards without reducing its frequency. Nishimoto and Tabei [CPM, 2021] proposed r-enum, an algorithm to enumerate various characteristic substrings, including maximal repeats, in a string T of length n in Oโข(r) words of compressed working space, where rโ‰คn is the number of runs in the Burrows-Wheeler transform (BWT) of T. Given the run-length encoded BWT (RLBWT) of T, r-enum runs in Oโข(nโขlogโกlogwโก(n/r)) time in addition to the time linear to the number of output strings, where w=ฮ˜โข(logโกn) is the word size. In this paper, we first improve the Oโข(nโขlogโกlogwโก(n/r)) term to Oโข(n). We next extend r-enum to compute other context-sensitive repeats such as near-supermaximal repeats (NSMRs) and supermaximal repeats, as well as the context diversity for every maximal repeat in the same complexities. Furthermore, we study net occurrences: An occurrence of a repeat is called a net occurrence if it is not covered by another repeat, and the net frequency of a repeat is the number of its net occurrences. With this terminology, an NSMR is a repeat with a positive net frequency. Given the RLBWT of T, we show how to compute the set ๐’ฎ๐—‡๐—Œ๐—†๐—‹ of all NSMRs in T together with their net frequency/occurrences in Oโข(n) time and Oโข(r) space. We also show that an Oโข(r)-space data structure can be built from the RLBWT to compute the net frequency/occurrences of any pattern in optimal time. The data structure is built in Oโข(r) space and in Oโข(n) time with high probability or deterministic Oโข(n+|๐’ฎ๐—‡๐—Œ๐—†๐—‹|โขlogโกlogโกminโก(ฯƒ,|๐’ฎ๐—‡๐—Œ๐—†๐—‹|)) time, where ฯƒโ‰คr is the alphabet size of T. To achieve this, we prove that the total number of net occurrences is less than 2โขr. With the duality between net occurrences and minimal unique substrings (MUSs), we get a new upper bound 2โขr of the number of MUSs in T, which may be of independent interest.

Keywords and phrases:
Supermaximal repeats, Largest maximal repeats, Net frequencies, Run-length Burrows-Wheeler transform, Compressed data mining
Funding:
Tomohiro I: KAKENHI 24K02899, JST AIP Acceleration Research JPMJCR24U4.
Copyright and License:
[Uncaptioned image]โ€‚ยฉ Kotaro Kimura and Tomohiro I; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation โ†’ Pattern matching
Related Version:
Previous Version: https://arxiv.org/abs/2511.11057
Editors:
Philip Bille and Nicola Prezza

1 Introduction

Finding characteristic substring patterns in a given string T is a fundamental task for string processing. One of the simplest patterns based on frequencies would be a repeat, which occurs at least twice in T. Since the number of distinct repeats in T of length n can be ฮ˜โข(n2), maximality is often utilized to reduce the number down to Oโข(n) [17]. A substring of T is called a right-maximal repeat (RMR) (resp. left-maximal repeat (LMR)) if it cannot be extended to the right (resp. to the left) without reducing its number of occurrences in T. If a repeat is both right-maximal and left-maximal, it is called a maximal repeat (MR).

Gusfield [17] also introduced stricter criteria to reduce the redundancy in maximal repeats. A repeat is called a supermaximal repeat (SMR) if it is not a substring of another repeat, and a near-supermaximal repeat (NSMR) if at least one of its occurrences is not covered by another repeat. It is easy to see that an SMR is an NSMR, and an NSMR is an MR. NSMRs were studied under the name of Chinese frequent strings in [21, 22, 32], and largest maximal repeats in [27, 11]. Gallรฉ and Tealdi [12, 13] proposed the concept of context diversities to define a general class of context-sensitive repeats including MRs and SMRs.

Enumerating these context-sensitive repeats has numerous applications in bioinformatics [17, 27, 2] and natural language processing [21, 22, 33, 24, 11] especially valuable for languages with no clear word segmentation such as Chinese and Japanese. Motivated by these applications, efficient enumeration algorithms have been extensively studied [33, 2, 31, 4, 30] using a family of suffix data structures such as suffix trees [35], directed acyclic word graphs (DAWGs) [8], compact DAWGs (CDAWGs) [7, 20], suffix arrays [23, 1] and Burrows-Wheeler transform (BWT) [9].

In this paper, we focus on r-enum [30], an algorithm to enumerate the MRs, minimal unique substrings (MUSs) [18] and minimal absent words (MAWs) in Oโข(r) words of compressed working space, where rโ‰คn is the number of runs in the BWT of T of length n. Given the run-length encoded BWT (RLBWT) of T, r-enum runs in Oโข(nโขlogโกlogwโก(n/r)) time in addition to the time linear to the number of output strings, where w=ฮ˜โข(logโกn) is the word size. We show that Oโข(nโขlogโกlogwโก(n/r)) time can be improved to Oโข(n) by resorting to the move data structure recently proposed by Nishimoto and Tabei [28] for constant-time LF-mapping on RLBWTs. We also extend r-enum to compute the NSMRs and SMRs, and the context diversity for every RMR in the same time and space complexities.

Furthermore, we consider problems for net occurrences and net frequencies, originated from the studies of Chinese frequent strings [21, 22] and have recently attracted attention from combinatorial and algorithmic points of view [14, 32, 16, 19, 15, 25]. An occurrence of a repeat is called a net occurrence if the occurrence is not covered by another repeat, and the net frequency of a repeat is the number of its net occurrences. We would like to point out the fact, which may have been overlooked for over two decades, that the strings with positive net frequencies are equivalent to the NSMRs [17] and the largest maximal repeats [27, 11], and thus appear to have broader applications. Also, net occurrences are conceptually equivalent to maximum repeats in [18].

Given the RLBWT of T, we show how to compute the set ๐’ฎ๐—‡๐—Œ๐—†๐—‹ of all NSMRs in T together with their net frequency/occurrences in Oโข(n) time and Oโข(r) words of space, solving the task called All-NF in [14] on RLBWTs. We also address the task called Single-NF [14], which requires building a data structure to support NF-queries of computing the net frequency and/or net occurrences of any query pattern. We show that an Oโข(r)-space data structure can be built from the RLBWT to support NF-queries in optimal time. The data structure is built in Oโข(r) space and in Oโข(n) time with high probability or deterministic Oโข(n+|๐’ฎ๐—‡๐—Œ๐—†๐—‹|โขlogโกlogโกminโก(ฯƒ,|๐’ฎ๐—‡๐—Œ๐—†๐—‹|)) time, where ฯƒโ‰คr is the alphabet size of T. To achieve this, we prove that the total number of net occurrences is less than 2โขr. With the duality between net occurrences and MUSs shown in [18, 25], we immediately get a new upper bound 2โขr of the number of MUSs in T, which may be of independent interest.

1.1 Related work

Context-sensitive repeats are closely related to and efficiently computed from suffix data structures. A folklore algorithm [17] uses suffix trees. To reduce the (rather big) working space of suffix trees by a constant factor, algorithms based on enhanced suffix arrays [1] have been proposed. A compact- or compressed-space solution can be achieved by using LF-mapping and range distinct queries (see Section 2) on BWTs or RLBWTs to simulate a traversal on suffix link trees. Table 1 summarizes representative algorithms.

Table 1: Comparison between algorithms that find characteristic substring patterns in a string T of length n over an integer alphabet of size ฯƒ=nOโข(1), where w=ฮ˜โข(logโกn) is the word size. Each method takes T, its BWT or Oโข(r)-size RLBWT as an input, and enumerate substring patterns represented in Oโข(1) space each. For MAWs, we additionally need the time linear to the number of output, which is bounded by Oโข(nโขฯƒ). RD represents a data structure for range distinct queries, which can be implemented in |๐‘…๐ท| bits of space while supporting a query in Oโข(d) time per output with (|๐‘…๐ท|,d)=(nโขlog2โกฯƒ+oโข(nโขlogโกฯƒ),Oโข(logโกฯƒ)) using Lemma 3 or (|๐‘…๐ท|,d)=(nโขlog2โกฯƒ+oโข(nโขlogโกฯƒ),Oโข(logโกฯƒ)) [10].
reference:
used techniques
space (bits) running time patterns
[17]: suffix tree Oโข(nโขlogโกn) Oโข(nโขlogโกฯƒ) MR, NSMR, SMR
[33]: enhanced suffix array Oโข(nโขlogโกn) Oโข(n) MR
[31]: enhanced suffix array Oโข(nโขlogโกn) Oโข(n)
MR, NSMR, SMR,
context diversity
[4]: BWT and RD Oโข(nโขlogโกฯƒ) Oโข(n) MR, MUS, MAW
[6]: BWT and RD |๐‘…๐ท|+Oโข(n) Oโข(nโขd) MR, SMR
[3]: BWT and RD |๐‘…๐ท|+Oโข(ฯƒ2โขlog2โกn) Oโข(nโขd) MR, MUS, MAW
[30]: RLBWT and RD Oโข(rโขlogโกn) Oโข(nโขlogโกlogwโก(n/r)) MR, MUS, MAW
this work:
RLBWT and RD
Oโข(rโขlogโกn) Oโข(n)
MR, MUS, MAW,
NSMR, SMR,
context diversity

The study for net frequencies/occurrences was initiated recently by Guo et al. [14]. Given a string T of length n over an integer alphabet of size ฯƒ=nOโข(1), we can perform All-NF in Oโข(n) time and words of space using an algorithm [31, 32] based on enhanced suffix arrays. The problem has also been studied in an online setting, where we maintain a data structure to perform All-NF and Single-NF while allowing monotonic updates to the left and/or right ends of T. The current state-of-the-art online algorithm [25] is based on online construction of implicit suffix trees and implicit CDAWGs. In this paper, we achieve the first offline algorithm for All-NF and Single-NF that works in Oโข(r) words of compressed space.

1.2 Organization of paper

This paper is organized as follows. In Section 2, we introduce notation and tools we use in the following sections. In Section 3, we prove that the total number of net occurrences is less than 2โขr, which is crucial to bound the time and space complexities of our algorithms for net frequencies/occurrences. In Section 4, we speed up r-enum and extend it to enumerate other context-sensitive repeats. In Section 5, we present an Oโข(r)-space data structure for NF-queries based on RLBWTs. In Section 6, we conclude the paper with some remarks.

2 Preliminaries

2.1 Basic notation

We assume a standard word-RAM model with word size w=ฮ˜โข(logโกn), where n is the length of string T defined later. A space complexity is evaluated by the number of words unless otherwise noted. Any integer treated in this paper is represented in Oโข(1) space, i.e., Oโข(w) bits. A set of consecutive integers is called an interval, which can be represented in Oโข(1) space by storing its beginning and ending integers. For two integers b and e, let [b..e] denote the interval {b,b+1,โ€ฆ,e} beginning at b and ending at e if bโ‰คe, and otherwise, the empty set. We also use [b..e):=[b..eโˆ’1] to exclude the right-end integer.

A string (or an array) x over a set S is a sequence xโข[1]โขxโข[2]โขโ‹ฏโขxโข[|x|], where |x| denotes the length of x and xโข[i]โˆˆS is the i-th element of x for any iโˆˆ[1..|x|]. The string of length 0 is called the empty string and denoted by ฮต. Let Sโˆ— denote the set of strings over S, and let SnโŠ‚Sโˆ— be the set of strings of length nโ‰ฅ0. For integers 1โ‰คbโ‰คeโ‰ค|x|, the substring of x beginning at b and ending at e is denoted by x[b..e]=x[b]x[b+1]โ‹ฏx[e]. For convenience, let x[b..e] with b>e represent the empty string. We also use x[b..e)=x[b..eโˆ’1] to exclude the right-end character. A prefix (resp. suffix) of x is a substring that matches x[1..e] (resp. x[b..|x|]) for some eโˆˆ[0..|x|] (resp. bโˆˆ[1..|x|+1]). We use the abbreviation x[..e]=x[1..e] and x[b..]=x[b..|x|]. For a non-negative integer d, let xd denote the string of length |x|โขd such that xd[|x|(iโˆ’1)+1..i|x|]=x for any iโˆˆ[1..d].

2.2 Tools

A function that injectively maps a set S of integers to [1..O(|S|)] can be used as a compact dictionary for S to look up a value associated with an integer in S. We use the following known result:

Lemma 1 ([36, 34]).

Given SโІ[1..u] of size mโ‰คuโ‰ค2Oโข(w), we can build an Oโข(m)-size dictionary in Oโข(m) time with high probability or deterministic Oโข(mโขlogโกlogโกm) time so that lookup queries can be supported in Oโข(1) worst-case time.

A predecessor query for an integer i over the set S of integers asks to compute maxโก{jโˆˆSโˆฃjโ‰คi}, which can be efficiently supported by the data structure of [5, Appendix A]:

Lemma 2 ([5]).

Given SโІ[1..u] of size mโ‰คuโ‰ค2Oโข(w), we can build an Oโข(m)-size data structure in Oโข(mโขlogโกlogwโก(u/m)) time and Oโข(m) space to support predecessor queries in Oโข(logโกlogwโก(u/m)) time for any iโˆˆ[1..n].

A range distinct query ๐–ฑ๐–ฃโข(x,p,q) for a string x and integers 1โ‰คpโ‰คqโ‰ค|x| asks to enumerate (c,pc,qc) such that pc and respectively qc are the smallest and largest positions in [p..q] with xโข[pc]=xโข[qc]=c for every distinct character c that occurs in x[p..q]. It is known that a range distinct query can be supported in output-optimal time after preprocessing x.

Lemma 3 ([26, 4]).

Given a string xโˆˆ[1..ฯƒ]m, we can build an Oโข(m)-size data structure in Oโข(m) time and space to support range distinct queries. With a null-initialized array of size ฯƒ, each query can be answered in Oโข(k) time, where k is the number of outputs.

A minor remark is that the output of range distinct queries of Lemma 3 may not be sorted in any order of characters.

2.3 Context-sensitive repeats

Let ฮฃ$=[1..ฯƒ] be an ordered alphabet with the smallest character $, and let ฮฃ=ฮฃ$โˆ–{$}. Throughout this paper, T[1..n]โˆˆฮฃ$n is a string of length nโ‰ฅ2 that contains all characters in ฮฃ$. 111If T is a string over a larger inefficient alphabet, we first replace every occurrence of a character with its rank in the character set actually used in T to satisfy the assumption. Given the RLBWT of T of size r, this task can be done in Oโข(n) time and Oโข(r) space using the sorting algorithm of [29, Lemma 13]. We assume for convenience that $ is used as a sentinel that exists at Tโข[n] and Tโข[0], and does not occur in T[1..nโˆ’1]. A position bโˆˆ[1..n] is called an occurrence of a string xโˆˆฮฃ$โˆ— in T if T[b..b+|x|)=x. Let ๐–ฎ๐–ผ๐–ผโข(x) denote the set of occurrences of x in T. The left context ๐—…๐–ผโข(x) (resp. right context ๐—‹๐–ผโข(x)) of a substring xโˆˆฮฃโˆ— of T is the set of characters immediately precedes (resp. follows) the occurrences of x, i.e., ๐—…๐–ผโข(x)={Tโข[bโˆ’1]โˆฃbโˆˆ๐–ฎ๐–ผ๐–ผโข(x)} (resp. ๐—‹๐–ผโข(x)={Tโข[b+|x|]โˆฃbโˆˆ๐–ฎ๐–ผ๐–ผโข(x)}). The context diversity of x is the pair (|๐—…๐–ผโข(x)|,|๐—‹๐–ผโข(x)|) of integers in [1..ฯƒ]. A substring x of T is called a repeat if |๐–ฎ๐–ผ๐–ผโข(x)|โ‰ฅ2, and called unique if |๐–ฎ๐–ผ๐–ผโข(x)|=1. A repeat xโˆˆฮฃโˆ— in T is a left-maximal repeat (LMR) (resp. right-maximal repeat (RMR)) if |๐—…๐–ผโข(x)|>1 (resp. |๐—‹๐–ผโข(x)|>1), and is a maximal repeat (MR) if x is both left- and right-maximal. A repeat x in T is a supermaximal repeat (SMR) if it is not a substring of another repeat. An occurrence b of a repeat x is called a net occurrence if there is no occurrence bโ€ฒ of another repeat xโ€ฒ such that [b..b+|x|)โŠ‚[bโ€ฒ..bโ€ฒ+|xโ€ฒ|). Let ๐–ญ๐–ฎ๐–ผ๐–ผโข(x)โІ๐–ฎ๐–ผ๐–ผโข(x) be the set of net occurrences of x and let ๐–ญ๐–ฅโข(x):=|๐–ญ๐–ฎ๐–ผ๐–ผโข(x)| be the number of net occurrences called the net frequency of x. A near-supermaximal repeat (NSMR) is a repeat with a positive net frequency. Let ๐’ฎ, ๐’ฎ๐—‹, ๐’ฎ๐—…๐—†๐—‹, ๐’ฎ๐—‹๐—†๐—‹, ๐’ฎ๐—†๐—‹, ๐’ฎ๐—‡๐—Œ๐—†๐—‹ and ๐’ฎ๐—Œ๐—†๐—‹ be the sets of all substrings, repeats, LMRs, RMRs, MRs, NSMRs and SMRs in T[1..n], respectively.

To describe algorithms uniformly, we assume that the empty string is a repeat that occurs at every position b in [1..n], i.e., ๐–ฎ๐–ผ๐–ผ(ฮต)=[1..n]. Since ๐—…๐–ผโข(ฮต)=๐—‹๐–ผโข(ฮต)=ฮฃ$, ฮต is always in ๐’ฎ๐—…๐—†๐—‹, ๐’ฎ๐—‹๐—†๐—‹ and ๐’ฎ๐—†๐—‹. We set the following exception for the definition of net occurrences of ฮต: An occurrence bโˆˆ๐–ฎ๐–ผ๐–ผโข(ฮต) is a net occurrence of ฮต if and only if Tโข[bโˆ’1] and Tโข[b] are both unique. This exception provides a smooth transition to another characterization of net occurrences based on the uniqueness of extended net occurrences [14, 25].

Table 3 summarizes the concepts introduced in this subsection for T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$.

Table 2: An example of the concepts introduced in Section 2.3 for T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$. For every repeat xโˆˆ๐’ฎ๐—‹, we show a visualization of the occurrences of x, ๐–ฎ๐–ผ๐–ผโข(x), ๐—…๐–ผโข(x), ๐—‹๐–ผโข(x), and the context diversity of x in the upper table. In the lower table, we show a visualization of the net occurrences of x, ๐–ญ๐–ฎ๐–ผ๐–ผโข(x), ๐–ญ๐–ฅโข(x), and subsequently check if x is in each of ๐’ฎ๐—…๐—†๐—‹, ๐’ฎ๐—‹๐—†๐—‹, ๐’ฎ๐—†๐—‹, ๐’ฎ๐—‡๐—Œ๐—†๐—‹ and ๐’ฎ๐—Œ๐—†๐—‹.
xโˆˆ๐’ฎ๐—‹ occurrences ๐–ฎ๐–ผ๐–ผโข(x) ๐—…๐–ผโข(x) ๐—‹๐–ผโข(x) context diversity
ฮต ยฏโข๐šŠโขยฏโข๐š‹โขยฏโข๐šŒโขยฏโข๐š‹โขยฏโข๐š‹โขยฏโข๐šŒโขยฏโข๐š‹โขยฏโข๐šŒโขยฏโข๐šŠโขยฏโข๐š‹โขยฏโข๐šŒโขยฏโข$ [1..12] {$,๐šŠ,๐š‹,๐šŒ} {$,๐šŠ,๐š‹,๐šŒ} (4,4)
๐šŠ ๐šŠยฏโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠยฏโข๐š‹โข๐šŒโข$ {1,9} {$,๐šŒ} {๐š‹} (2,1)
๐š‹ ๐šŠโข๐š‹ยฏโข๐šŒโข๐š‹ยฏโข๐š‹ยฏโข๐šŒโข๐š‹ยฏโข๐šŒโข๐šŠโข๐š‹ยฏโข๐šŒโข$ {2,4,5,7,10} {๐šŠ,๐š‹,๐šŒ} {๐š‹,๐šŒ} (3,2)
๐šŒ ๐šŠโข๐š‹โข๐šŒยฏโข๐š‹โข๐š‹โข๐šŒยฏโข๐š‹โข๐šŒยฏโข๐šŠโข๐š‹โข๐šŒยฏโข$ {3,6,8,11} {๐š‹} {$,๐šŠ,๐š‹} (1,3)
๐šŠ๐š‹ ๐šŠโข๐š‹ยฏโข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹ยฏโข๐šŒโข$ {1,9} {$,๐šŒ} {๐šŒ} (2,1)
๐š‹๐šŒ ๐šŠโข๐š‹โข๐šŒยฏโข๐š‹โข๐š‹โข๐šŒยฏโข๐š‹โข๐šŒยฏโข๐šŠโข๐š‹โข๐šŒยฏโข$ {2,5,7,10} {๐šŠ,๐š‹,๐šŒ} {$,๐šŠ,๐š‹} (3,3)
๐šŒ๐š‹ ๐šŠโข๐š‹โข๐šŒโข๐š‹ยฏโข๐š‹โข๐šŒโข๐š‹ยฏโข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ {3,6} {๐š‹} {๐š‹,๐šŒ} (1,2)
๐šŠ๐š‹๐šŒ ๐šŠโข๐š‹โข๐šŒยฏโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒยฏโข$ {1,9} {$,๐šŒ} {$,๐š‹} (2,2)
๐š‹๐šŒ๐š‹ ๐šŠโข๐š‹โข๐šŒโข๐š‹ยฏโข๐š‹โข๐šŒโข๐š‹ยฏโข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ {2,5} {๐šŠ,๐š‹} {๐š‹,๐šŒ} (2,2)
xโˆˆ๐’ฎ๐—‹ net occurrences ๐–ญ๐–ฎ๐–ผ๐–ผโข(x) ๐–ญ๐–ฅโข(x) LMR RMR MR NSMR SMR
ฮต ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ โˆ… 0 โˆš โˆš โˆš
๐šŠ ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ โˆ… 0 โˆš
๐š‹ ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ โˆ… 0 โˆš โˆš โˆš
๐šŒ ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ โˆ… 0 โˆš
๐šŠ๐š‹ ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ โˆ… 0 โˆš
๐š‹๐šŒ ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒยฏโข๐šŠโข๐š‹โข๐šŒโข$ {7} 1 โˆš โˆš โˆš โˆš
๐šŒ๐š‹ ๐šŠโข๐š‹โข๐šŒโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ โˆ… 0 โˆš
๐šŠ๐š‹๐šŒ ๐šŠโข๐š‹โข๐šŒยฏโข๐š‹โข๐š‹โข๐šŒโข๐š‹โข๐šŒโข๐šŠโข๐š‹โข๐šŒยฏโข$ {1,9} 2 โˆš โˆš โˆš โˆš โˆš
๐š‹๐šŒ๐š‹ ๐šŠโข๐š‹โข๐šŒโข๐š‹ยฏโข๐š‹โข๐šŒโข๐š‹ยฏโข๐šŒโข๐šŠโข๐š‹โข๐šŒโข$ {2,5} 2 โˆš โˆš โˆš โˆš โˆš

2.4 Suffix trees and suffix arrays

The suffix trie of T is the tree defined on the set ๐’ฎ of nodes and edges from xโˆˆ๐’ฎ to xโขcโˆˆ๐’ฎ with cโˆˆฮฃ$. The suffix tree of T is the compacted suffix trie in which every non-branching internal node of the suffix trie is removed and considered to be an implicit node. Every internal node of the suffix tree is a right-maximal repeat x and has |๐—‹๐–ผโข(x)| children. A link from a node x to a (possibly implicit) node aโขxโˆˆ๐’ฎ for some aโˆˆฮฃ$ is called a Weiner link. It is known that every node can be reached by following Weiner links from the root ฮต, and the total number of Weiner links is at most 3โขn, which can be seen from the duality between suffix trees and DAWGs [8].

The suffix array ๐–ฒ๐– [1..n] of T is the integer array such that, for any iโˆˆ[1..n], T[๐–ฒ๐– [i]..] is the lexicographically i-th suffix among the non-empty suffixes of T. For any string xโˆˆ๐’ฎ, the SA-interval of x, denoted by โ„โข(x), is the maximal interval [p..q] such that x is a prefix of T[๐–ฒ๐– [i]..] for any iโˆˆ[p..q]. Then, it holds that ๐–ฎ๐–ผ๐–ผโข(x)={๐–ฒ๐– โข[i]โˆฃiโˆˆโ„โข(x)}.

2.5 Burrows-Wheeler transform

The Burrows-Wheeler transform (BWT) ๐–ซ[1..n] of T is the string such that ๐–ซโข[i]=Tโข[๐–ฒ๐– โข[i]โˆ’1] for any iโˆˆ[1..n]. Note that Tโข[๐–ฒ๐– โข[i]โˆ’1]=Tโข[0]=$ for i with ๐–ฒ๐– โข[i]=1 due to the sentinel at Tโข[0]. By definition, it holds that ๐—…๐–ผโข(x)={๐–ซโข[i]โˆฃiโˆˆโ„โข(x)} for any string x. The LF-mapping ๐–ซ๐–ฅ is the permutation on [1..n] such that ๐–ซ๐–ฅโข(i) represents the lexicographic rank of the suffix T[๐–ฒ๐– [i]โˆ’1..] if ๐–ฒ๐– โข[i]โ‰ 1, and otherwise ๐–ซ๐–ฅโข(i)=1. The FL-mapping ๐–ฅ๐–ซ is the inverse mapping of ๐–ซ๐–ฅ. Given an integer i in โ„โข(x) for a string x, we can compute x by using FL-mapping |x| times from i because xโข[k]=๐–ซโข[๐–ฅ๐–ซkโข(i)] holds for any kโข(1โ‰คkโ‰ค|x|), where ๐–ฅ๐–ซkโข(i) is defined recursively ๐–ฅ๐–ซkโข(i)=๐–ฅ๐–ซโข(๐–ฅ๐–ซkโˆ’1โข(i)) with the base case ๐–ฅ๐–ซ1โข(i)=๐–ฅ๐–ซโข(i).

Table 3 shows an example of ๐–ฒ๐– , ๐–ซ๐–ฅโข(โ‹…), ๐–ฅ๐–ซโข(โ‹…) and ๐–ซ for T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$. Figure 1 also illustrates the suffix tree of T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$ and a relationship between Weiner links and BWTs.

Table 3: An example of ๐–ฒ๐– โข[i], ๐–ซ๐–ฅโข(i), ๐–ฅ๐–ซโข(i) and ๐–ซโข[i] for T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$.
i ๐–ฒ๐– โข[i] ๐–ซ๐–ฅโข(i) ๐–ฅ๐–ซโข(i) ๐–ซโข[i] T[๐–ฒ๐– [i]..]
1 12 9 3 ๐šŒ $
2 9 10 5 ๐šŒ ๐šŠ๐š‹๐šŒโข$
3 1 1 7 $ ๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
4 4 11 8 ๐šŒ ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
5 10 2 9 ๐šŠ ๐š‹๐šŒโข$
6 7 12 10 ๐šŒ ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
7 2 3 11 ๐šŠ ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
8 5 4 12 ๐š‹ ๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
9 11 5 1 ๐š‹ ๐šŒโข$
10 8 6 2 ๐š‹ ๐šŒ๐šŠ๐š‹๐šŒโข$
11 3 7 4 ๐š‹ ๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
12 6 8 6 ๐š‹ ๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$
Figure 1: The left figure shows the suffix tree of T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$ illustrated over sorted suffixes, on which each node x can be represented by โ„โข(x) and |x|. A solid box is a node (highlighted for internal nodes), and a dotted box is an implicit node. The right figure shows the Weiner links outgoing from all internal nodes (the Weiner links from leaves are omitted). The Weiner links that points to internal nodes are depicted with solid arrows, and the other ones with dotted arrows. Observe that there is a Weiner link from a node x to aโขx for any character aโˆˆ๐—…๐–ผโข(x)={๐–ซโข[i]โˆฃiโˆˆโ„โข(x)}, where the case with a=$ is excluded unless x=ฮต.

The run-length encoded BWT (RLBWT) of T represents ๐–ซ in Oโข(r) space by string ๐–ซโ€ฒ[1..r]โˆˆฮฃ$r and array ๐–ฝ[1..r]โˆˆ[1..n]r such that ๐–ซ=๐–ซโ€ฒโข[1]๐–ฝโข[1]โข๐–ซโ€ฒโข[2]๐–ฝโข[2]โขโ€ฆโข๐–ซโ€ฒโข[r]๐–ฝโข[r] and ๐–ซโ€ฒโข[i]โ‰ ๐–ซโ€ฒโข[j] for any 1โ‰คi<jโ‰คr. Each component ๐–ซโ€ฒโข[i]๐–ฝโข[i] is called a run of ๐–ซ. While rโ‰คn is obvious, inequality ฯƒโ‰คr holds under the assumption that T contains all characters in ฮฃ$.

Example 4.

For T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$, its BWT ๐–ซ=๐šŒ๐šŒโข$๐šŒ๐šŠ๐šŒ๐šŠ๐š‹๐š‹๐š‹๐š‹๐š‹ has r=7 runs. Then, we have ๐–ซโ€ฒ=๐šŒโข$๐šŒ๐šŠ๐šŒ๐šŠ๐š‹ and ๐–ฝ=[2,1,1,1,1,1,5].

A notable property of ๐–ซ๐–ฅ is that ๐–ซ๐–ฅโข(i)=k1+k2 holds, where k1 is the number of characters smaller than ๐–ซโข[i] in ๐–ซ and k2 is the number of occurrences of ๐–ซโข[i] in ๐–ซ[1..i]. In particular, if ๐–ซ[p..q] consists of a single character, then ๐–ซ๐–ฅโข(i)=๐–ซ๐–ฅโข(p)+iโˆ’p for any iโˆˆ[p..q], and ๐–ฅ๐–ซโข(iโ€ฒ)=๐–ฅ๐–ซโข(pโ€ฒ)+iโ€ฒโˆ’pโ€ฒ for any iโ€ฒโˆˆ[pโ€ฒ..qโ€ฒ] with pโ€ฒ=๐–ซ๐–ฅโข(p) and qโ€ฒ=๐–ซ๐–ฅโข(q). Hence, LF-mapping can be implemented in Oโข(r) space by constructing the predecessor data structure for the set of beginning positions of runs of ๐–ซ and remembering the ๐–ซ๐–ฅโข(โ‹…) values for those positions (FL-mapping can be implemented similarly). Using the predecessor data structure of Lemma 2, we get:

Lemma 5.

Given the RLBWT of T, we can construct an Oโข(r)-size data structure in Oโข(rโขlogโกlogwโก(n/r)) time and Oโข(r) space to compute ๐–ซ๐–ฅโข(i) and ๐–ฅ๐–ซโข(i) in Oโข(logโกlogwโก(n/r)) time for any iโˆˆ[1..n].

Nishimoto and Tabei [28] proposed a novel data structure, called the move data structure, to implement LF-mapping by a simple linear search on a list of intervals without predecessor queries. We consider a list [p1..p2),[p2..p3),โ€ฆ,[pr^..pr^+1) of r^=Oโข(r) intervals such that p1=1, pr^+1=n+1, and for any kโˆˆ[1..r^], ๐–ซ[pk..pk+1) consists of a single character and [๐–ซ๐–ฅ(pk)..๐–ซ๐–ฅ(pk+1โˆ’1)] intersects with Oโข(1) intervals in the list. We let each [pk..pk+1) have a pointer to the interval [pkโ€ฒ..pkโ€ฒ+1) that contains ๐–ซ๐–ฅโข(pk) and offset ok=๐–ซ๐–ฅโข(pk)โˆ’pkโ€ฒ. Then, ๐–ซ๐–ฅโข(i)=๐–ซ๐–ฅโข(pk)+iโˆ’pk=pkโ€ฒ+ok+iโˆ’pk holds for any iโˆˆ[pk..pk+1). Given i and interval [pk..pk+1) that contains i, we can compute ๐–ซ๐–ฅโข(i) and find the interval that contains ๐–ซ๐–ฅโข(i) by assessing Oโข(1) intervals from [pkโ€ฒ..pkโ€ฒ+1) to the right in the list. Note that ๐–ซ๐–ฅโข(i) computation on the move data structure works along with the pointer to the interval in the list that contains i, which is handled implicitly hereafter. Under the assumption that ฯƒโ‰คr in this paper, we can construct the data structure needed for LF-mapping (and FL-mapping) in Oโข(rโขlogโกr) time [29, Appendix D]:

Lemma 6.

Given the RLBWT of T, we can construct an Oโข(r)-size data structure in Oโข(rโขlogโกr) time and Oโข(r) space to compute ๐–ซ๐–ฅโข(i) and ๐–ฅ๐–ซโข(i) in Oโข(1) time for any iโˆˆ[1..n].

3 Upper bound ๐Ÿโข๐’“ of net occurrences and MUSs

In this section, we consider combinatorial properties of net occurrences on BWTs.

We start with the following lemma.

Lemma 7.

For any integer iโˆˆ[p..q]=โ„(x) for a repeat x of T, ๐–ฒ๐– โข[i] is a net occurrence of x if and only if ๐–ซโข[i] is unique in ๐–ซ[p..q] and T[๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|] is unique in T.

Proof.

If a=๐–ซโข[i] is not unique in ๐–ซ[p..q], then ๐–ฒ๐– โข[i] is not a net occurrence of x because ax=T[๐–ฒ๐– [i]โˆ’1..๐–ฒ๐– [i]+|x|) is a repeat that covers [๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|). Similarly, if T[๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|] is not unique in T, then ๐–ฒ๐– โข[i] is not a net occurrence of x because T[๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|] is a repeat that covers [๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|).

On the other hand, if ๐–ซโข[i] is unique in ๐–ซ[p..q] and T[๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|] is unique in T, there is no repeat that covers [๐–ฒ๐– [i]..๐–ฒ๐– [i]+|x|), and hence, ๐–ฒ๐– โข[i] is a net occurrence of x. โ—€

Example 8.

Let us consider a repeat ๐š‹๐šŒ with โ„โข(๐š‹๐šŒ)=[5..8] in the example of Table 3. ๐–ฒ๐– โข[6]=7 is a net occurrence of ๐š‹๐šŒ because ๐–ซโข[6]=๐šŒ is unique in ๐–ซโข[5..8]=๐šŠ๐šŒ๐šŠ๐š‹, and T[๐–ฒ๐– [6]..๐–ฒ๐– [6]+2]=T[7..9]=๐š‹๐šŒ๐šŠ is unique in T. ๐–ฒ๐– โข[5]=10 and ๐–ฒ๐– โข[7]=2 are not net occurrences of ๐š‹๐šŒ because ๐–ซโข[5]=๐–ซโข[7]=๐šŠ is not a unique character in ๐–ซโข[5..8]. ๐–ฒ๐– โข[7]=2 and ๐–ฒ๐– โข[8]=5 are not net occurrences of ๐š‹๐šŒ because Tโข[2..4]=Tโข[5..7]=๐š‹๐šŒ๐š‹ is a repeat.

The following lemma was implicitly proved in [14, Theorem 24] to show the total length of all net occurrences is bounded by twice the sum of irreducible longest common prefixes.

Lemma 9.

If ๐–ฒ๐– โข[i] is a net occurrence of a repeat x of T, then i is at the beginning or ending position of a run in ๐–ซ, and ๐–ฒ๐– โข[i] cannot be a net occurrence of another repeat.

Proof.

Let [p..q]=โ„(x). If iโˆˆ[p..q] is not at the runโ€™s boundaries of ๐–ซ, then at least one of ๐–ซโข[i]=๐–ซโข[i+1] with i+1โˆˆ[p..q] or ๐–ซโข[iโˆ’1]=๐–ซโข[i] with iโˆ’1โˆˆ[p..q] holds, which means that ๐–ฒ๐– โข[i] is not a net occurrence of x by Lemma 7. ๐–ฒ๐– โข[i] cannot be a net occurrence of two distinct repeats, since otherwise, the occurrence of the shorter repeat is covered by the longer one. โ—€

Lemma 9 leads to the following theorem:

Theorem 10.

The total number of net occurrences of T is less than 2โขr.

Proof.

Let r1 and respectively r>1 be the number of runs in ๐–ซ of length 1 and longer than 1, i.e., r=r1+r>1. Since there are r1+2โขr>1 positions that correspond to beginning or ending positions of runs in ๐–ซ, it is clear from Lemma 9 that the total number of net occurrences is at most r1+2โขr>1โ‰ค2โขr. The number is shown to be less than 2โขr by looking closer at some special positions like 1 and n on ๐–ซ: Since ๐–ฒ๐– โข[1] (resp. ๐–ฒ๐– โข[n]) cannot be a net occurrence if the first (resp. last) run of ๐–ซ is longer than 1, only one net occurrence is charged to the first (resp. last) run of ๐–ซ. โ—€

A non-empty interval [b..e] is called a minimal unique substring (MUS) if T[b..e] is unique while T[b+1..e] and T[b..eโˆ’1] are repeats. In [18, 25], it has been proved that the net occurrences and MUSs are dual concepts, basically saying that for any two consecutive MUSs [b..e] and [bโ€ฒ..eโ€ฒ] with b<bโ€ฒ, b+1 is a net occurrence of T[b+1..eโ€ฒโˆ’1]. With this duality, we immediately get the following:

Corollary 11.

The number of MUSs of T is less than 2โขr.

4 R-enum revisited

4.1 Rough sketch of r-enum and speedup

Conceptually, r-enum performs a breadth-first traversal on the internal nodes ๐’ฎ๐—‹๐—†๐—‹ of the suffix tree by following Weiner links using RLBWT-based data structures. Each node xโˆˆ๐’ฎ๐—‹๐—†๐—‹ is visited with its suffix interval โ„โข(x) and length |x| together with the information about its right extensions ๐—‹๐—…๐—‚๐—Œ๐—โข(x), which is the list of the set {(c,โ„โข(xโขc))โˆฃcโˆˆ๐—‹๐–ผโข(x)} sorted by the character c. The triplet ๐—‹๐–พ๐—‰๐—‹โข(x)=(โ„โข(x),๐—‹๐—…๐—‚๐—Œ๐—โข(x),|x|) is called the rich representation [4, 30] of x, which can be stored in Oโข(|๐—‹๐–ผโข(x)|) space.

Given ๐—‹๐–พ๐—‰๐—‹(x)=([p..q],{(ci,[pi..qi])}i=1k,|x|), we can compute {๐—‹๐–พ๐—‰๐—‹โข(aโขx)โˆฃaโขxโˆˆ๐’ฎ,aโˆˆฮฃ} as follows: A null-initialized array A[1..ฯƒ] is used as a working space to build ๐—‹๐—…๐—‚๐—Œ๐—โข(aโขx) at Aโข[a] for aโˆˆ๐—…๐–ผโข(x)โˆ–{$}. For every iโˆˆ[1..k], we compute ๐—…๐–ผโข(xโขci) by a range distinct query on ๐–ซ[pi..qi], and for each aโˆˆ๐—…๐–ผโข(xโขci)โˆ–{$} we compute โ„โข(aโขxโขci) by LF-mapping and append (ci,โ„โข(aโขxโขci)) to the list being built at Aโข[a]. After processing all iโˆˆ[1..k], Aโข[a] becomes ๐—‹๐—…๐—‚๐—Œ๐—โข(aโขx). Finally, we enumerate ๐—…๐–ผโข(x) by a range distinct query on ๐–ซ[p..q] to go through only the used entries of A to compute ๐—‹๐–พ๐—‰๐—‹โข(aโขx) and clear the entries. For the next round of the breadth-first traversal on ๐’ฎ๐—‹๐—†๐—‹, we keep only the set {๐—‹๐–พ๐—‰๐—‹โข(aโขx)โˆฃaโขxโˆˆ๐’ฎ๐—‹๐—†๐—‹}, discarding ๐—‹๐–พ๐—‰๐—‹โข(aโขx) if ๐—‹๐—…๐—‚๐—Œ๐—โข(aโขx) contains only one element.

Example 12.

In the r-enum for T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$, we visit a repeat ๐š‹๐šŒโˆˆ๐’ฎ๐—‹๐—†๐—‹ with its rich representation ๐—‹๐–พ๐—‰๐—‹โข(๐š‹๐šŒ)=(โ„โข(๐š‹๐šŒ),๐—‹๐—…๐—‚๐—Œ๐—โข(๐š‹๐šŒ),|๐š‹๐šŒ|)=([5..8],{($,[5..5]),(๐šŠ,[6..6]),(๐š‹,[7..8])},2). With a null-initialized array A[1..ฯƒ], we compute ๐—‹๐–พ๐—‰๐—‹โข(๐šŠ๐š‹๐šŒ)=([2..3],{($,[2..2]),(๐š‹,[3..3])},3) at Aโข[๐šŠ], ๐—‹๐–พ๐—‰๐—‹โข(๐š‹๐š‹๐šŒ)=([4..4],{(๐š‹,[4..4])},3) at Aโข[๐š‹], and ๐—‹๐–พ๐—‰๐—‹โข(๐šŒ๐š‹๐šŒ)=([12..12],{(๐šŠ,[12..12])},3) at Aโข[๐šŒ].

R-enum executes the above procedure in Oโข(r) space using range distinct queries on ๐–ซโ€ฒ[1..r] and RLBWT-based LF-mapping. The breadth-first traversal on ๐’ฎ๐—‹๐—†๐—‹ can be made in Oโข(r) space because the space needed to store the rich representations for all strings in {aโขxโˆˆ๐’ฎโˆฃaโˆˆฮฃ,xโˆˆ๐’ฎ๐—‹๐—†๐—‹,|x|=t} for any tโˆˆ[0..n] was proved to be Oโข(r) in Section 3.3 of [30]. The total number of outputs of range distinct queries is upper bounded by Oโข(n) because each output can be charged to a distinct Weiner link. Similarly, the total number of LF-mapping needed is bounded by Oโข(n).

The original r-enum used Lemma 5 to implement LF-mapping and runs in Oโข(nโขlogโกlogwโก(n/r)) time in total (excluding the time to output patterns for MAWs). We show that this can be improved to Oโข(n) time.

Theorem 13.

Given the RLBWT of T, r-enum runs in Oโข(r) working space and Oโข(n) time in addition to the time linear to the number of output strings.

Proof.

If r=ฮฉโข(n/logโกn), the original r-enum with Lemma 5 is already upper bounded by Oโข(n) because Oโข(nโขlogโกlogwโก(n/r))=Oโข(nโขlogโกlogwโกlogโกn) and w=ฮ˜โข(logโกn). For the case with r=oโข(n/logโกn), we use the move data structure of Lemma 6 to implement LF-mapping, which can be constructed in Oโข(rโขlogโกr)=Oโข(n) time. Since LF-mapping can be done in Oโข(1) time on the move data structure, the r-enum runs in Oโข(n) time. โ—€

4.2 Extension for NSMRs, SMRs, and context diversities

In this subsection, we extend r-enum to compute the NSMRs and SMRs, and the context diversity for every RMR. Since ๐’ฎ๐—Œ๐—†๐—‹โІ๐’ฎ๐—‡๐—Œ๐—†๐—‹โІ๐’ฎ๐—†๐—‹โІ๐’ฎ๐—‹๐—†๐—‹ holds, for enumerating SMRs (resp. NSMRs), it is enough to check every element in ๐’ฎ๐—‹๐—†๐—‹ if it is in ๐’ฎ๐—Œ๐—†๐—‹ (resp. ๐’ฎ๐—‡๐—Œ๐—†๐—‹).

Recall that r-enum traverses xโˆˆ๐’ฎ๐—‹๐—†๐—‹ while computing {๐—‹๐–พ๐—‰๐—‹โข(aโขx)โˆฃaโขxโˆˆ๐’ฎ} from ๐—‹๐–พ๐—‰๐—‹(x)=([p..q],{(ci,[pi..qi])}i=1k,|x|). First, we can compute the context diversity (|๐—…๐–ผโข(x)|,|๐—‹๐–ผโข(x)|) of xโˆˆ๐’ฎ๐—‹๐—†๐—‹ because |๐—‹๐–ผโข(x)| is k and |๐—…๐–ผโข(x)| is the number of outputs of a range distinct query on ๐–ซ[p..q]. Since x is an SMR if and only if |๐—…๐–ผโข(x)|=|๐—‹๐–ผโข(x)|=|๐–ฎ๐–ผ๐–ผโข(x)|=qโˆ’p+1, the context diversity has enough information to choose SMRs from RMRs. On the other hand, NSMRs cannot be determined from the context diversities.

To determine if xโˆˆ๐’ฎ๐—‹๐—†๐—‹ is an NSMR or not, we check if there is a net occurrence of x in {๐–ฒ๐– [j]โˆฃjโˆˆ[p..q]} using the array A[1..ฯƒ] that stores ๐—‹๐—…๐—‚๐—Œ๐—โข(aโขx) at Aโข[a] for any aโˆˆ๐—…๐–ผโข(x)โˆ–{$}. Thanks to Lemma 7, we only have to consider ๐–ฒ๐– โข[pi] for intervals [pi..qi] with pi=qi as candidates of net occurrences. For an interval [pi..qi] with pi=qi, we check if a=๐–ซโข[pi] is $ or โ„โข(aโขx) computed in Aโข[a] is a singleton, and then, ๐–ฒ๐– โข[pi] is a net occurrence if and only if the condition holds. We can also compute ๐–ญ๐–ฎ๐–ผ๐–ผโข(x) if we store ๐–ฒ๐– โข[i] for all runโ€™s boundaries i, which can be precomputed using LF-mapping Oโข(n) times.

Since we can check the conditions for NSMRs and SMRs along with the traversal of ๐’ฎ๐—‹๐—†๐—‹, the time and space complexities of r-enum are retained.

Theorem 14.

Given the RLBWT of T, we can compute the NSMRs and SMRs, and the context diversity for every RMR in Oโข(n) time and Oโข(r) working space. The net occurrences of output patterns can also be computed in the same time and space complexities.

5 An ๐‘ถโข(๐’“)-size data structure for NF-queries

In this section, we tackle the problem called Single-NF [14] on RLBWTs: We consider preprocessing the RLBWT of T to construct a data structure of size Oโข(r) so that we can support NF-queries of computing ๐–ญ๐–ฅโข(P) for any query pattern P.

We define the reversed trie for a set S of strings as follows:

  • โ– 

    The nodes consist of the suffixes of strings in S.

  • โ– 

    There is an edge from node x to aโขx with a character a.

Theorem 15.

Given the RLBWT of T, we can build an Oโข(r)-size data structure in Oโข(r) space and in Oโข(n) time with high probability or deterministic Oโข(n+|๐’ฎ๐—‡๐—Œ๐—†๐—‹|โขlogโกlogโกminโก(ฯƒ,|๐’ฎ๐—‡๐—Œ๐—†๐—‹|)) time to support NF-queries for any query pattern P in Oโข(|P|) time.

Proof.

We execute r-enum of Theorem 14, which actually performs a breadth-first traversal of the reversed trie for ๐’ฎ๐—‹๐—†๐—‹ in Oโข(n) time and Oโข(r) space. Our idea is to build the compacted reversed trie ๐’ฏ for ๐’ฎ๐—‡๐—Œ๐—†๐—‹ during the traversal, which can be stored in Oโข(|๐’ฎ๐—‡๐—Œ๐—†๐—‹|)=Oโข(r) space because |๐’ฎ๐—‡๐—Œ๐—†๐—‹|โ‰ค2โขr by Lemma 9. For each node x of ๐’ฏ, which corresponds to a string in ๐’ฎ๐—‡๐—Œ๐—†๐—‹ or a branching node, we store the string length |x| and an integer ix in โ„โข(x) so that the edge label between x and its parent y can be retrieved by using FL-mapping |x|โˆ’|y| times from ix. For a node xโˆˆ๐’ฎ๐—‡๐—Œ๐—†๐—‹, we also store the net frequency of x. See Figure 2 for an illustration of ๐’ฏ.

We show that we can build ๐’ฏ in Oโข(n) time and Oโข(r) working space during the breadth-first traversal of r-enum. For each string depth t, we maintain the compacted reversed trie ๐’ฏt for the set ๐’ฎt๐—‹๐—†๐—‹โˆช๐’ฎโ‰คt๐—‡๐—Œ๐—†๐—‹, where ๐’ฎt๐—‹๐—†๐—‹ is the set of RMRs of length t and ๐’ฎโ‰คt๐—‡๐—Œ๐—†๐—‹ is the set of NSMRs of length โ‰คt. Since |๐’ฎt๐—‹๐—†๐—‹|=Oโข(r) and |๐’ฎโ‰คt๐—‡๐—Œ๐—†๐—‹|=Oโข(r), the size of ๐’ฏt is Oโข(r). In the next round of the breadth-first traversal, r-enum extends every string in ๐’ฎt๐—‹๐—†๐—‹ by one character to the left to get ๐’ฎt+1๐—‹๐—†๐—‹. We update ๐’ฏt to ๐’ฏt+1 by processing xโˆˆ๐’ฎt๐—‹๐—†๐—‹ as follows, where Ax={aโขxโˆฃaโขxโˆˆ๐’ฎt+1๐—‹๐—†๐—‹}:

  • โ– 

    If |Ax|โ‰ฅ2, we add new edges from x to the strings in Ax.

  • โ– 

    If |Ax|=1, we add a new edge from x to the string in Ax, and remove the non-branching node x if x is not an NSMR.

  • โ– 

    If |Ax|=0 and xโˆ‰๐’ฎ๐—‡๐—Œ๐—†๐—‹, we remove the node x and the edge to its parent y. We also remove y, if it becomes a non-branching node not in ๐’ฎ๐—‡๐—Œ๐—†๐—‹.

In total, these tasks can be done in Oโข(n) time and Oโข(r) space along with r-enum of Theorem 14. For each branching node of ๐’ฏ with kโ‰คminโก(ฯƒ,|๐’ฎ๐—‡๐—Œ๐—†๐—‹|) outgoing edges, we build a dictionary of Lemma 1 in Oโข(k) space and Oโข(k) time w.h.p. or deterministic Oโข(kโขlogโกlogโกminโก(ฯƒ,k)) time so that we can decide which child to proceed by the first characters of edges in Oโข(1) time. The construction time of the dictionaries for all branching nodes is bounded by Oโข(|๐’ฎ๐—‡๐—Œ๐—†๐—‹|) time w.h.p. or deterministic Oโข(|๐’ฎ๐—‡๐—Œ๐—†๐—‹|โขlogโกlogโกminโก(ฯƒ,|๐’ฎ๐—‡๐—Œ๐—†๐—‹|)) time.

Given a query pattern P, we read the characters of P from right to left and traverse ๐’ฏ from the root in Oโข(|P|) time. If we can reach a node Pโˆˆ๐’ฎ๐—‡๐—Œ๐—†๐—‹, we output ๐–ญ๐–ฅโข(P) stored in the node. โ—€ We can also support queries of computing the net occurrences of a query pattern P in Oโข(|P|+|๐–ญ๐–ฎ๐–ผ๐–ผโข(P)|) time by storing ๐–ญ๐–ฎ๐–ผ๐–ผโข(x) for each node xโˆˆ๐’ฎ๐—‡๐—Œ๐—†๐—‹ in ๐’ฏ, which can be stored in Oโข(r) space in total due to Lemma 9.

Figure 2: An illustration of the compacted reversed trie ๐’ฏ for ๐’ฎ๐—‡๐—Œ๐—†๐—‹={๐š‹๐šŒ,๐šŠ๐š‹๐šŒ,๐š‹๐šŒ๐š‹} in our running example T=๐šŠ๐š‹๐šŒ๐š‹๐š‹๐šŒ๐š‹๐šŒ๐šŠ๐š‹๐šŒโข$. A node corresponding to an NSMR is highlighted. Storing ๐–ญ๐–ฎ๐–ผ๐–ผโข(โ‹…) is optional. Note that edge labels are not stored explicitly. For example, the string ๐š‹๐šŒ๐š‹ on the edge from ฮต to ๐š‹๐šŒ๐š‹ is retrieved using FL-mapping i๐š‹๐šŒ๐š‹โˆ’iฮต=3 times from i๐š‹๐šŒ๐š‹=7 when necessary.

6 Conclusions

We improved the time complexity of r-enum, and extended its enumeration power for other context-sensitive repeats in the literature. We also proposed the first data structure of size Oโข(r) to support NF-queries in optimal time, which can be regarded as an Oโข(r)-space representation of ๐’ฎ๐—‡๐—Œ๐—†๐—‹ with the help of RLBWTs. As a combinatorial property, we formally proved that the total number of net occurrences, as well as MUSs, is upper bounded by Oโข(r).

We note that our enumeration algorithm runs independently of the alphabet size ฯƒ thanks to the output-optimal range distinct queries of Lemma 3. The space usage depending on ฯƒ is hidden behind Oโข(r). We removed the dependence on ฯƒ in the NF-query time by using a dictionary with worst-case constant-time lookup.

Finally, we remark that our work leads to the first algorithm to compute the sorted list of net occurrences and MUSs in Oโข(n) time and Oโข(r) space: We enumerate all net occurrences by Theorem 13, and sort them in Oโข(n) time and Oโข(r) space by [29, Lemma 13].

References

  • [1] Mohamed Ibrahim Abouelhoda, Stefan Kurtz, and Enno Ohlebusch. Replacing suffix trees with enhanced suffix arrays. Journal of Discrete Algorithms, 2(1):53โ€“86, 2004. doi:10.1016/S1570-8667(03)00065-0.
  • [2] Verรณnica Becher, Alejandro Deymonnaz, and Pablo Ariel Heiber. Efficient computation of all perfect repeats in genomic sequences of up to half a gigabyte, with a case study on the human genome. Bioinform., 25(14):1746โ€“1753, 2009. doi:10.1093/BIOINFORMATICS/BTP321.
  • [3] Djamal Belazzougui and Fabio Cunial. Space-efficient detection of unusual words. In Costas S. Iliopoulos, Simon J. Puglisi, and Emine Yilmaz, editors, Proc. 22nd International Symposium on String Processing and Information Retrieval (SPIRE) 2015, volume 9309 of Lecture Notes in Computer Science, pages 222โ€“233. Springer, 2015. doi:10.1007/978-3-319-23826-5_22.
  • [4] Djamal Belazzougui, Fabio Cunial, Juha Kรคrkkรคinen, and Veli Mรคkinen. Linear-time string indexing and analysis in small space. ACM Trans. Algorithms, 16(2):17:1โ€“17:54, 2020. doi:10.1145/3381417.
  • [5] Djamal Belazzougui and Gonzalo Navarro. Optimal lower and upper bounds for representing sequences. ACM Trans. Algorithms, 11(4):31:1โ€“31:21, 2015. doi:10.1145/2629339.
  • [6] Timo Beller, Katharina Berger, and Enno Ohlebusch. Space-efficient computation of maximal and supermaximal repeats in genome sequences. In Liliana Calderรณn-Benavides, Cristina N. Gonzรกlez-Caro, Edgar Chรกvez, and Nivio Ziviani, editors, Proc. 19th International Symposium on String Processing and Information Retrieval (SPIRE) 2012, volume 7608 of Lecture Notes in Computer Science, pages 99โ€“110. Springer, 2012. doi:10.1007/978-3-642-34109-0_11.
  • [7] Anselm Blumer, J. Blumer, David Haussler, Ross M. McConnell, and Andrzej Ehrenfeucht. Complete inverted files for efficient text retrieval and analysis. J. ACM, 34(3):578โ€“595, 1987. doi:10.1145/28869.28873.
  • [8] Anselm Blumer, Janet Blumer, David Haussler, Andrzej Ehrenfeucht, M. T. Chen, and Joel Seiferas. The smallest automaton recognizing the subwords of a text. Theoretical Computer Science, 40:31โ€“55, 1985. doi:10.1016/0304-3975(85)90157-4.
  • [9] Michael Burrows and David J Wheeler. A block-sorting lossless data compression algorithm. Technical report, HP Labs, 1994.
  • [10] Francisco Claude, Gonzalo Navarro, and Alberto Ordรณรฑez Pereira. The wavelet matrix: An efficient wavelet tree for large alphabets. Inf. Syst., 47:15โ€“32, 2015. doi:10.1016/J.IS.2014.06.002.
  • [11] Matthias Gallรฉ. The bag-of-repeats representation of documents. In Gareth J. F. Jones, Paraic Sheridan, Diane Kelly, Maarten de Rijke, and Tetsuya Sakai, editors, Proc. 36th International ACM SIGIR conference on research and development in Information Retrieval 2013, pages 1053โ€“1056. ACM, 2013. doi:10.1145/2484028.2484142.
  • [12] Matthias Gallรฉ and Matรญas Tealdi. On context-diverse repeats and their incremental computation. In Adrian-Horia Dediu, Carlos Martรญn-Vide, Josรฉ Luis Sierra-Rodrรญguez, and Bianca Truthe, editors, Proc. 8th International Conference on Language and Automata Theory and Applications (LATA) 2014, volume 8370 of Lecture Notes in Computer Science, pages 384โ€“395. Springer, 2014. doi:10.1007/978-3-319-04921-2_31.
  • [13] Matthias Gallรฉ and Matรญas Tealdi. xkcd-repeats: A new taxonomy of repeats defined by their context diversity. J. Discrete Algorithms, 48:1โ€“16, 2018. doi:10.1016/J.JDA.2017.10.005.
  • [14] Peaker Guo, Patrick Eades, Anthony Wirth, and Justin Zobel. Exploiting new properties of string net frequency for efficient computation. In Shunsuke Inenaga and Simon J. Puglisi, editors, Proc. 35th Annual Symposium on Combinatorial Pattern Matching (CPM) 2024, volume 296 of LIPIcs, pages 16:1โ€“16:16. Schloss Dagstuhl โ€“ Leibniz-Zentrum fรผr Informatik, 2024. doi:10.4230/LIPIcs.CPM.2024.16.
  • [15] Peaker Guo and Kaisei Kishi. Net occurrences in fibonacci and thue-morse words. In Paola Bonizzoni and Veli Mรคkinen, editors, Proc. 36th Annual Symposium on Combinatorial Pattern Matching (CPM) 2025, volume 331 of LIPIcs, pages 16:1โ€“16:22. Schloss Dagstuhl โ€“ Leibniz-Zentrum fรผr Informatik, 2025. doi:10.4230/LIPIcs.CPM.2025.16.
  • [16] Peaker Guo, Seeun William Umboh, Anthony Wirth, and Justin Zobel. Online computation of string net frequency. In Zsuzsanna Liptรกk, Edleno Silva de Moura, Karina Figueroa, and Ricardo Baeza-Yates, editors, Proc. 31st International Symposium on String Processing and Information Retrieval (SPIRE) 2024, volume 14899 of Lecture Notes in Computer Science, pages 159โ€“173. Springer, 2024. doi:10.1007/978-3-031-72200-4_12.
  • [17] Dan Gusfield. Algorithms on Strings, Trees, and Sequences - Computer Science and Computational Biology. Cambridge University Press, 1997. doi:10.1017/CBO9780511574931.
  • [18] Lucian Ilie and William F. Smyth. Minimum unique substrings and maximum repeats. Fundam. Informaticae, 110(1-4):183โ€“195, 2011. doi:10.3233/FI-2011-536.
  • [19] Shunsuke Inenaga. Faster and simpler online computation of string net frequency, 2024. arXiv:2410.06837. doi:10.48550/arXiv.2410.06837.
  • [20] Shunsuke Inenaga, Hiromasa Hoshino, Ayumi Shinohara, Masayuki Takeda, Setsuo Arikawa, Giancarlo Mauri, and Giulio Pavesi. On-line construction of compact directed acyclic word graphs. Discrete Applied Mathematics, 146(2):156โ€“179, 2005. doi:10.1016/J.DAM.2004.04.012.
  • [21] Yih-Jeng Lin and Ming-Shing Yu. Extracting chinese frequent strings without dictionary from a chinese corpus, its applications. J. Inf. Sci. Eng., 17(5):805โ€“824, 2001. URL: http://www.iis.sinica.edu.tw/page/jise/2001/200109_07.html.
  • [22] Yih-Jeng Lin and Ming-Shing Yu. The properties and further applications of chinese frequent strings. Int. J. Comput. Linguistics Chin. Lang. Process., 9(1), 2004. URL: http://www.aclclp.org.tw/clclp/v9n1/v9n1a7.pdf.
  • [23] Udi Manber and Eugene W. Myers. Suffix arrays: A new method for on-line string searches. SIAM J. Comput., 22(5):935โ€“948, 1993. doi:10.1137/0222058.
  • [24] Tomonari Masada, Atsuhiro Takasu, Yuichiro Shibata, and Kiyoshi Oguri. Clustering documents with maximal substrings. In Proc. 13th International Conference on Enterprise Information Systems ICEIS 2011, pages 19โ€“34, 2011. doi:10.1007/978-3-642-29958-2_2.
  • [25] Takuya Mieno and Shunsuke Inenaga. Space-efficient online computation of string net occurrences. In Paola Bonizzoni and Veli Mรคkinen, editors, Proc. 36th Annual Symposium on Combinatorial Pattern Matching (CPM) 2025, volume 331 of LIPIcs, pages 23:1โ€“23:13. Schloss Dagstuhl โ€“ Leibniz-Zentrum fรผr Informatik, 2025. doi:10.4230/LIPIcs.CPM.2025.23.
  • [26] S. Muthukrishnan. Efficient algorithms for document retrieval problems. In Proc. 13th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA) 2002, pages 657โ€“666, 2002. URL: http://dl.acm.org/citation.cfm?id=545381.545469.
  • [27] Jacques Nicolas, Christine Rousseau, Anne Siegel, Pierre Peterlongo, Franรงois Coste, Patrick Durand, Sรฉbastien Tempel, Anne-Sophie Valin, and Frรฉdรฉric Mahรฉ. Modeling local repeats on genomic sequences. Research Report RR-6802, INRIA, 2008. URL: https://inria.hal.science/inria-00353690.
  • [28] Takaaki Nishimoto and Yasuo Tabei. Optimal-time queries on BWT-runs compressed indexes. In Nikhil Bansal, Emanuela Merelli, and James Worrell, editors, Proc. 48th International Colloquium on Automata, Languages and Programming (ICALP) 2021, volume 198 of LIPIcs, pages 101:1โ€“101:15. Schloss Dagstuhl โ€“ Leibniz-Zentrum fรผr Informatik, 2021. doi:10.4230/LIPIcs.ICALP.2021.101.
  • [29] Takaaki Nishimoto and Yasuo Tabei. Optimal-time queries on BWT-runs compressed indexes, 2021. arXiv:2006.05104v3.
  • [30] Takaaki Nishimoto and Yasuo Tabei. R-enum: Enumeration of characteristic substrings in BWT-runs bounded space. In Pawel Gawrychowski and Tatiana Starikovskaya, editors, Proc. 32nd Annual Symposium on Combinatorial Pattern Matching (CPM) 2021, volume 191 of LIPIcs, pages 21:1โ€“21:21. Schloss Dagstuhl โ€“ Leibniz-Zentrum fรผr Informatik, 2021. doi:10.4230/LIPIcs.CPM.2021.21.
  • [31] Enno Ohlebusch and Timo Beller. Alphabet-independent algorithms for finding context-sensitive repeats in linear time. J. Discrete Algorithms, 34:23โ€“36, 2015. doi:10.1016/J.JDA.2015.05.005.
  • [32] Enno Ohlebusch, Thomas Bรผchler, and Jannik Olbrich. Faster computation of chinese frequent strings and their net frequencies. In Zsuzsanna Liptรกk, Edleno Silva de Moura, Karina Figueroa, and Ricardo Baeza-Yates, editors, Proc. 31st International Symposium on String Processing and Information Retrieval (SPIRE) 2024, volume 14899 of Lecture Notes in Computer Science, pages 249โ€“256. Springer, 2024. doi:10.1007/978-3-031-72200-4_19.
  • [33] Daisuke Okanohara and Junโ€™ichi Tsujii. Text categorization with all substring features. In Proc. SIAM International Conference on Data Mining (SDM) 2009, pages 838โ€“846, 2009. doi:10.1137/1.9781611972795.72.
  • [34] Milan Ruzic. Constructing efficient dictionaries in close to sorting time. In Proc. 35th International Colloquium on Automata, Languages and Programming (ICALP) 2008, pages 84โ€“95, 2008. doi:10.1007/978-3-540-70575-8_8.
  • [35] Peter Weiner. Linear pattern-matching algorithms. In Proc. 14th IEEE Ann. Symp. on Switching and Automata Theory, pages 1โ€“11, 1973. doi:10.1109/SWAT.1973.13.
  • [36] Dan E. Willard. Examining computational geometry, van emde boas trees, and hashing from the perspective of the fusion tree. SIAM J. Comput., 29(3):1030โ€“1049, 2000. doi:10.1137/S0097539797322425.