# Indexing Strings with Utilities

Giulia Bernardini<fnref n="1" />, Huiping Chen², Alessio Conte³, Roberto Grossi³, Veronica Guerrini³, Grigorios Loukides<fnref n="4" />, Nadia Pisanti³, and Solon P. Pissis⁵

**Abstract**—Applications in domains ranging from bioinformatics to advertising feature strings (sequences of letters over some alphabet) that come with numerical scores (*utilities*). The utilities quantify the importance, interest, profit, or risk of the letters occurring at every position of a string. For instance, DNA fragments generated by sequencing machines come with a confidence score per position. Motivated by the ever-increasing rate of generating such data, as well as by their importance in several domains, we introduce Useful String Indexing (USI), a natural generalization of the classic String Indexing problem. Given a string *S* (the *text*) of length *n*, USI asks for preprocessing *S* into a compact data structure supporting the following queries efficiently: given a shorter string *P* (the *pattern*), return the global utility *U*(*P*) of *P* in *S*, where *U* is a function that maps any string *P* to a utility score based on the utilities of the letters of every occurrence of *P* in *S*. Our work also makes the following contributions: (1) We propose a novel and efficient data structure for USI based on finding the top-*K* frequent substrings of *S*. (2) We propose a linear-space data structure that can be used to mine the top-*K* frequent substrings of *S* or to tune the parameters of the USI data structure. (3) We propose a novel space-efficient algorithm for estimating the set of the top-*K* frequent substrings of *S*, thus improving the construction space of the data structure for USI. (4) We show that popular space-efficient top-*K* frequent item mining strategies employed by state-of-the-art algorithms do not smoothly translate from *items* to *substrings*. (5) Using billion-letter datasets, we experimentally demonstrate that: (i) our top-*K* frequent substring mining algorithms are accurate and scalable, unlike two state-of-the-art methods; and (ii) our USI data structures are up to 15 times faster in querying than 4 nontrivial baselines while occupying the same space with them.

## I. INTRODUCTION

Many application domains feature *strings* (sequences of letters over some alphabet) associated with numerical scores (*utilities*). The utilities quantify the importance, interest, profit, or risk of the letters occurring at every position of such strings [1], [2], [3], [4]; see Fig. 1. In bioinformatics, sequencing machines assign to each nucleotide a confidence score that represents the probability that this nucleotide has been correctly read by the machine and helps to identify sequencing errors [5]. Thus, a DNA fragment is represented by a string where each letter is associated with a probability. In networks, each sensor is often assigned a Received Signal Strength Index (RSSI); i.e., a signal strength value that helps assessing network link quality [6]. Thus, a sequence of sensor readings is represented by a string where each letter is associated with an RSSI. In advertising, each advertisement is often associated with a Click-Through Rate (CTR): an estimate

<figure><img src="image_1.png" /><figcaption>Fig. 1: Illustration of real strings with associated utilities.</figcaption></figure>

of the probability that a user clicks on the advertisement, which helps advertisement pricing [7]. Thus, a sequence of advertisements is represented by a string where each letter is associated with a CTR. In web analytics, each visited web page in a web server log is often associated with a score equal to the browsing time of the web page, which serves as a proxy of its importance [1]. Thus, a web server log is represented by a string where each letter is associated with such a score. In marketing, each product is often associated with a profit made by a sale [1]. Thus, a sequence of products is represented by a string where each letter is associated with a profit.

Although strings with utilities are crucial to analyze in many application domains, existing research, which has been developed for more than 15 years, focuses solely on the *mining* of patterns from such strings (see [1] for a survey). However, *querying* such strings to find the utility of a query pattern is equally important. For example, in bioinformatics, researchers are interested in evaluating the quality of a DNA pattern by computing its expected frequency in a collection of DNA strings with confidence scores [8]. In advertising, evaluating the effectiveness of a series of advertisements is crucial for performing *ad sequencing* (i.e., finding a good order of showing the advertisements to users), which increases consumers' interest or reinforces a message [9] and is supported by Google Ads and YouTube. In web analytics, finding the total time spent visiting a sequence of web pages can improve website services, offer navigation recommendations, and improve web page design [10], [1]. In marketing, computing the total profit made by selling some products in a certain order and/or comparing the profits made by selling products in

<footnote n="1">¹University of Trieste, Trieste, Italy ²University of Birmingham, Birmingham, UK ³University of Pisa, Pisa, Italy</footnote>

<footnote n="4">⁴King's College London, London, UK ⁵CWI & Vrije Universiteit, Amsterdam, The Netherlands</footnote>
different orders helps understanding consumers' behavior [11] as well as formulating commodity promotion and commodity procurement strategies [12]. In all these examples, the length of the strings is in the order of millions or billions, whereas the patterns are relatively short and occur a very large number of times [13], [14], [15].

In response, we introduce the USEFUL STRING INDEXING (USI) problem, informally defined as follows (see Section III for a formal definition): Let $S$ be a string of length $n$ (the text), $w$ be a weight function that assigns to each position of $S$ a utility, $u$ be a local utility function that aggregates the utilities of the positions of an occurrence of a string $P$ in $S$, and $U$ be a global utility function that aggregates the local utility of all occurrences of $P$ in $S$. The problem is to construct a data structure to answer the following queries: given a string $P$ (the pattern) of length $m$, return the global utility $U(P)$ of $P$.

**Example 1.** Consider the string $S$ below and the utilities of its positions assigned by $w$. Consider also the following global utility function [11]: $U(P)$ sums up the local utilities of all the occurrences of $P$ in $S$, where the local utility of an occurrence of $P$ is the sum of the utilities of its letters. Let $P = TACCCC$. $P$ occurs in $S$ at positions 1 and 12. USI returns $U(P) = (1+3+2+0.7+1+1)+(1+1+1+0.9+1+1) = 14.6$.

<table><thead><tr><th>i</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th><th>11</th><th>12</th><th>13</th><th>14</th><th>15</th><th>16</th><th>17</th><th>18</th><th>19</th></tr></thead><tbody><tr><td>S</td><td>A</td><td>T</td><td>A</td><td>C</td><td>C</td><td>C</td><td>C</td><td>G</td><td>A</td><td>T</td><td>A</td><td>A</td><td>T</td><td>A</td><td>C</td><td>C</td><td>C</td><td>C</td><td>A</td><td>G</td></tr><tr><td>w</td><td>.9</td><td>1</td><td>3</td><td>2</td><td>.7</td><td>1</td><td>1</td><td>.6</td><td>.5</td><td>.5</td><td>.5</td><td>.8</td><td>1</td><td>1</td><td>1</td><td>.9</td><td>1</td><td>1</td><td>.8</td><td>1</td></tr></tbody></table>

We remark that indexing is arguably a more general problem than mining [8], as one can use USI to: (1) query all patterns $P$ that are substrings of $S$, thus mining all patterns satisfying a global utility (or a length) constraint; (2) query any set of arbitrary patterns that are of interest in a specific setting.

**Why is USI Challenging?** USI can be solved by constructing a classic text index over $S$, such as the suffix tree [16] or the suffix array [17], finding the occurrences of the query pattern $P$ in $S$ and then computing and returning the global utility $U(P)$. The downside of this simple approach is that the computation of $U(P)$ requires aggregating the local utilities of all occurrences of $P$, and this takes a large amount of time in practice for queries with reasonably many occurrences (e.g., in DNA sequencing data the occurrences are in the order of millions while $P$ is typically short [13]). This happens regardless of the way the global utility $U(P)$ is computed. Indeed, the simplest approach is to compute the local utility of each occurrence by applying the function $w$ to each position of an occurrence and then aggregating the results of all occurrences to obtain $U(P)$. This takes $O(m \cdot |occ_S(P)|)$ time, where $m$ is the length of $P$ and $|occ_S(P)|$ is the number of occurrences of $P$ in $S$. When the local utility function has the sliding-window property (see Section III), a more efficient approach is to use prefix-sums: we precompute the local utility of each prefix of $S$ and obtain the local utility of $P$ occurring at position $i$ as a function of the local utility of two prefixes of $S$, $S[0..i+m-1]$ and $S[0..i-1]$. Then, we aggregate the results as in the simple approach. The precomputation takes $O(n)$ time and computing a single local utility of $P$ takes

<figure><img src="image_2.png" /><figcaption>Fig. 2: Overview of our approach for USI.</figcaption></figure>

$O(1)$ time and thus $O(m + |occ_S(P)|)$ time in total for $U(P)$. Unfortunately, the query time is a function of $|occ_S(P)|$, thus it still requires a long time for frequent patterns, as these patterns have a very large number of occurrences.

**Overview of our Approach.** To address USI efficiently, we propose to combine two different indexing schemes (see Fig. 2): one dedicated to queries with many occurrences; and a second index for the rest of the queries. Since every substring of $S$ could potentially be a query pattern $P$, we decompose the substrings of $S$ into the top-$K$ frequent substrings, whose global utility is the most expensive to compute, and the rest of the substrings. For the frequent substrings, we use an explicit representation of size $O(K)$: we precompute their global utilities using a sliding-window approach and store them in a hash table. Each hash table key is the fingerprint [18] of a frequent substring of $S$ and the value is the global utility of the substring. Since we can read the global utility from the hash table in $O(1)$ time, the query time for a frequent substring is $O(m)$: the time to compute the fingerprint of $P$. The infrequent substrings are not represented explicitly: we index them by means of a classic text index over $S$ [16] of size $O(n)$; and the computation of global utilities is offloaded to the query part which employs the prefix-sums approach. Let $\tau_K$ be the minimum support of the top-$K$ frequent substrings; $K$ can be efficiently determined by a data structure that we propose. Since computing a single local utility using prefix-sums takes $O(1)$ time, the query time for an infrequent substring is $O(m + \tau_K)$: the time to search $P$ in the text index plus the time to compute the local utilities of at most $\tau_K$ occurrences. Thus, the query time for any $P$ is bounded by $O(m + \tau_K)$ and the size of the data structure is bounded by $O(n + K)$.

**Example 2.** A bioinformatics researcher routinely evaluates the quality of DNA patterns of length 8 [19] occurring in a genomic dataset [20] with total size $n \approx 2.9 \cdot 10^9$. They indexed the dataset using a classic index (suffix array [17]) and computed the global utility of 5,000 DNA patterns of length 8, randomly selected from the top-$(n/50)$ frequent substrings, based on the prefix-sums approach discussed earlier. The least frequent of these patterns occurred 104,262 times. The average query time was $0.1 \cdot 10^{-3}$ seconds. Using our approach with $K := n/100 \approx 2.9 \cdot 10^7$ instead, the average query time was $0.7 \cdot 10^{-6}$ seconds (i.e., it was almost three orders of magnitude faster). The size of the suffix array index was 85.31 GBs, and the size of our index was 86.38 GBs.

The most crucial steps in our approach are to (i) efficiently
<table><caption>TABLE I: (a) Top-4 substrings with respect to global utility, among those having length at least 3, and their global utility ranks and scores (i.e., sum of their CTRs). (b) Top-4 frequent patterns with length at least 3, and their global utility ranks and scores (i.e., sum of their CTRs). (c) Cluster categories and the letters they correspond to in Tables Ia and Ib.</caption><tr><td>Substring Rank</td><td>aba</td><td>ccc</td><td>aaa</td><td>ded</td></tr><tr><td>Utility U</td><td>4075.6</td><td>3998.3</td><td>3229.5</td><td>2885.8</td></tr></table>

(a)

<table><tr><td>Substring Rank</td><td>ddf</td><td>ffe</td><td>fef</td><td>gba</td></tr><tr><td>Utility U</td><td>1658.9</td><td>1224.2</td><td>1222.3</td><td>1226.5</td></tr></table>

(b)

<table><tr><td>Letter Keyword</td><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>f</td><td>g</td></tr><tr><td></td><td>Credit reporting</td><td>Money making</td><td>Mortgages</td><td>Credit cards</td><td>Financial trading</td><td>Non-vehicle insurance</td><td>Web/software hosting</td></tr></table>

(c)

compute the top-K frequent substrings of S and (ii) efficiently construct the hash table. Surprisingly, computing the top-K frequent substrings has not been considered explicitly in the literature, unlike finding top-K frequent items. As we show, existing approaches for computing top-K frequent items [21], [22] cannot be modified to effectively compute top-K frequent substrings. Therefore, for step (i), we propose two algorithms to compute the top-K frequent substrings. The first algorithm computes the exact set $T_K$ of top-K frequent substrings in $O(n+K)$ time by combining efficient indexes of S and sorting. The second algorithm estimates $T_K$ but is more space-efficient: it uses space $O(n/s+K)$ and requires $\tilde{O}(n+sK)$ time, for a user-defined parameter $s$, which trades time efficiency and accuracy for space; the $\tilde{O}$ notation suppresses polylog($n$) factors. By combining the output of either of the two algorithms, an index of S, and a sliding-window approach, we can perform step (ii) efficiently. In particular, we bound the time complexity for step (ii) by $O(nL_K)$, where $L_K$ is the number of distinct lengths of the K reported substrings. We will show that $L_K$ is actually small in practice for suitable choices of K (or $\tau$).

**Contributions.** We introduce the USI problem for indexing a string S with utilities and make the following contributions.

1. We propose a novel, efficient data structure for USI based on finding the top-K frequent substrings of S (Section IV).

2. We propose a linear-space data structure that can be used to mine the top-K frequent substrings of S or to tune the parameter K or $\tau$ in order to estimate the query time, size, and construction time of the USI data structure (Section V).

3. We propose a novel, space-efficient algorithm for estimating the set of top-K frequent substrings of S, thus improving the construction space of the USI data structure (Section VI).

4. We consider modifying frequent item mining algorithms to estimate the set of top-K frequent substrings. In particular, we demonstrate theoretically that popular space-efficient top-K frequent item mining strategies [23], [21], [22], employed by state-of-the-art algorithms [24], [25], do not smoothly translate from items to substrings and thus lead to very inaccurate estimations of the top-K frequent substrings (Section VII).

5. We perform an extensive experimental study to assess the efficiency and effectiveness of all the proposed methods using 5 datasets of sizes up to 4.6 billion letters (Section IX). We first show that our algorithm for estimating the set of top-K frequent substrings is remarkably effective and 8.6 times more space-efficient on average than the exact method. On the contrary, approaches based on state-of-the-art algorithms [24], [25] for estimating top-K frequent substrings are much less effective and/or less efficient. For instance, on the genomic dataset of Example 2 and over a wide range of K values, our

algorithm had an average accuracy of 97.5% and took at most 8.7 hours. On the contrary, an approach based on a state-of-the-art algorithm [24] had an average accuracy of 64.6% and did not finish within 5 days for the largest K. We then show that our data structure for USI offers on average 3.1 times (and up to 15 times) more efficient query answering than 4 nontrivial baselines, which employ advanced string processing tools, while occupying a similar amount of memory than them.

We organize the remainder of the paper as follows. In Section II, we present a case study using a real advertising dataset (with CTR data) to showcase the applicability of our methods. In Section III, we present the necessary definitions and notation. We discuss related work in Section VIII. We conclude the paper in Section X with some future directions.

## II. CASE STUDY

Consider: (1) An advertising company whose string S (the text) is comprised of advertisements with a Click-Through Rate (CTR) assigned to each position to model its utility. (2) Marketers who are interested in determining whether their own patterns of advertisements are sufficiently effective, according to the past experience of the advertising company, which is captured by S. This operation helps marketers perform ad sequencing, as mentioned in Section I. The effectiveness of a marketer's pattern P can be measured by summing up the CTRs of all advertisements in an occurrence of P in S, to obtain the local utility of that occurrence, and then summing up the local utilities of all occurrences of P in S, to obtain the global utility $U(P)$. The effectiveness of P can be determined efficiently by indexing S using our USI data structure and querying it using P. To demonstrate the applicability of our data structure, we used an advertising dataset from [26] that we preprocessed by clustering its keyword phrases (advertisements) into 14 categories, using an automated tool [27] and manual post-processing [28]. We then replaced each advertisement by its category, but we retained the CTR of the advertisement. This led to a text, ADV, of length 218,987 over an alphabet of size 14. We used each substring of ADV with length in [3, 200] as a marketer's pattern P, and the total query time for all 187,883 such patterns was 3.4 seconds. This highlights the efficiency of our data structure.

We also considered a setting where the advertising company wants to find the most useful substrings of length at least 3 from S based on the same function U. We constructed our USI data structure, used each substring of S with length at least 3 as a query, and sorted the substrings in terms of decreasing global utility. The top-4 substrings in terms of global utility and their global utilities are in Table Ia. Interestingly, these are different from the top-4 frequent substrings in ADV (see Table Ib) and
have much larger utilities (e.g., the most frequent substring in Table Ib has the 21st largest global utility among those mined by our method). Furthermore, they are comprised of more semantically similar advertisements (e.g., credit reporting and money making vs. credit cards and non-vehicle insurance); see Table Ic. This highlights the usefulness of our data structure.

### III. PRELIMINARIES AND PROBLEM DEFINITIONS

**Strings.** An alphabet $\Sigma$ is a finite set of elements called letters. This can be any finite set; e.g., a set of integers (or reals). A string $S = S[0..n-1]$ of length $|S| = n$ is a sequence of $n$ letters from $\Sigma$, where $S[i]$ denotes the $i$th letter of the sequence. We refer to each $i \in [0, n)$ as a position of $S$. We consider throughout that $\Sigma = [0, \sigma)$ is an integer alphabet of size $\sigma$, such that $\sigma = n^{\mathcal{O}(1)}$; i.e., $\sigma$ is polynomial in $n$. For instance, $\Sigma$ can be the set of integers from 0 to 9 and $S = 0124966$ is a string over this integer alphabet $\Sigma = [0, 9]$.

A substring $R$ of $S$ may occur multiple times in $S$. The set of its occurrences in $S$ is denoted by $\mathbf{occ}_S(R)$, and its frequency by $|\mathbf{occ}_S(R)|$; we may omit the subscript $S$ when it is clear from the context. An occurrence of $R$ in $S$ starting at position $i$ is referred to as a fragment of $S$ and is denoted by $\mathbf{frag}_S(i, |R|) = S[i..i+|R|-1]$. Thus, different fragments may correspond to different occurrences of the same substring. A prefix of $S$ is a substring of the form $S[0..j]$, and a suffix of $S$ is a substring of the form $S[i..n-1]$. It should thus be clear that any fragment of $S$ is a prefix of some suffix of $S$.

Karp-Rabin (KR) fingerprints (or fingerprints for short) is a rolling hash method, introduced by Karp and Rabin [18]. It associates strings to integers in such a way that, with high probability, no collision occurs among the substrings of a given string. The KR fingerprints for all the length-$k$ substrings of a string $S$, $k > 0$, can be computed in $O(|S|)$ total time [18].

We consider the following basic string problem that determines which substrings of $S$ will be explicitly stored in the hash table index of our data structure for the USI problem.

**Problem 1 (TOP-K-SUB).** Given a string $S$ of length $n$ and an integer $K > 0$, return the $K$ most frequent substrings of $S$ (breaking ties arbitrarily).

**Utility Definitions.** Let $S$ be a string of length $n$ and let $w: [0, n) \to \mathbb{R}$ be a function that assigns to each position $i \in [0, n)$ of $S$ a real number $w[i]$, referred to as the utility of $S[i]$. We may refer to the pair $(S, w)$ as a weighted string. For any fragment $\mathbf{frag}_S(i, |R|)$, a local utility function $u(i, |R|)$ aggregates the utilities of all letters of the fragment (i.e., aggregates $w[k]$, for each $k \in [i, i+|R|-1]$). For any substring $R$ of $S$, a global utility function $U(R)$ aggregates the value of the local utility of all the occurrences of the substring in $S$.

We define a class $\mathbb{U}$ of global utility functions, such that for every $U \in \mathbb{U}$: (1) $U$ is linear-time computable (e.g., sum, min, max, or avg); and (2) the local utility function of $U$ has the sliding-window property (e.g., sum): for any three fragments of $S$, $S[i..j]$, its prefix $S[i..i']$, $i \le i'$, and its suffix $S[i'+1..j]$, $i'+1 \le j$, the local utility of any of these

three fragments can be obtained from the local utilities of the other two in $O(1)$ time. We consider the following problem.

**Problem 2 (USEFUL STRING INDEXING (USI)).** Given a string $S$ of length $n$, a weight function $w$, and a global utility function $U$ from class $\mathbb{U}$, construct a data structure that answers queries of the following type: given a string $P$ of length $m$, return the global utility $U(P)$ of $P$.

**String Indexes.** A trie $T(S)$ is a rooted tree whose nodes represent the prefixes of strings in a set $S$ of strings [29] over alphabet $\Sigma$. The edges of a tree are labeled by letters from $\Sigma$; the prefix corresponding to node $v$ is denoted by $\text{str}(v)$ and is given by the concatenation of the letters labeling the path (sequence of edges) from the root to $v$. The node $v$ is called the locus of $\text{str}(v)$. The order on $\Sigma$ induces an order on the edges outgoing from any node of $T(S)$. A node $v$ is branching if it has at least two children and terminal if $\text{str}(v) \in S$.

A compacted trie is obtained from $T(S)$ by dissolving all nodes except the root, the branching nodes, and the terminal nodes. The dissolved nodes are called implicit while the preserved nodes are called explicit. The edges of the compacted trie are labeled by strings. The string depth $\text{sd}(v) = |\text{str}(v)|$ of any node $v$ is the length of the string it represents, i.e., the total length of the strings labeling the path from the root to $v$. The frequency $f(v)$ of node $v$ is the number of terminal nodes in the subtree rooted at $v$. The compacted trie takes $O(|S|)$ space provided that edge labels are stored as pointers to fragments of strings in $S$. Given the lexicographic order on $S$ along with the lengths of the longest common prefixes between any two consecutive (in this order) elements of $S$, one can compute the compacted trie of $S$ in $O(|S|)$ time [30].

The suffix tree of a string $S$, denoted by $\text{ST}(S)$, is the compacted trie of the set of all suffixes of $S$. Each terminal node in $\text{ST}$ is labeled by the starting position in $S$ of the suffix it represents. $\text{ST}(S)$ can be constructed in $O(n)$ time for any string $S$ of length $n$ over $\Sigma = [0, n^{\mathcal{O}(1)}]$ [16]. The suffix array of $S$, denoted by $\text{SA}(S)$ [17], is the permutation of $[0, n)$ such that $\text{SA}[i]$ is the starting position of the $i$th lexicographically smallest suffix of $S$. It can be constructed in $O(n)$ time for any string $S$ of length $n$ over $\Sigma = [0, n^{\mathcal{O}(1)}]$ [16]. The LCP($S$) array [17] of $S$ stores the length of longest common prefixes of lexicographically adjacent suffixes. For $j > 0$, LCP[$j$] stores the length of the longest common prefix between the suffixes $\text{SA}[j-1]$ and $\text{SA}[j]$, and LCP[$0$] = 0. Given the $\text{SA}$ of $S$, we can compute the LCP array of $S$ in $O(n)$ time [30].

### IV. DATA STRUCTURE FOR USEFUL STRING INDEXING

In this section, we describe an efficient data structure for USI (Problem 2). It is constructed for a weighted string $(S, w)$ of length $n$ and any global utility function $U$ from class $\mathbb{U}$, and it is parameterized by an integer $K \in [1, n^2]$. This parameter is defined by the user, and it trades query time for space, as we will explain in Section V. Recall that a query consists of a string $P$ of length $m$, and we aim to return its global utility $U(P)$ fast. Our data structure relies on a precomputed set $T_K$ of top-$K$ frequent substrings, whose efficient computation will
be discussed in Section V. Let $\tau_K$ be the smallest frequency of any substring from $T_K$, and $L_K$ be the number of distinct lengths of the substrings in $T_K$. Our data structure, coined USI$_{TOP-K}$, achieves the bounds stated by Theorem 1.

**Theorem 1.** USI can be solved for any weighted string $(S, w)$ of length $n$, any global utility function $U \in \mathbb{U}$, and any parameter $K \in [1, n^2]$, with a data structure that can be constructed in $O(nL_K)$ time, has size $O(n+K)$, and answers queries in $O(m+\tau_K)$ time. The construction space on top of the space needed by $(S, w)$ is $O(n+K)$.

Before describing USI$_{TOP-K}$, let us comment on the bounds it achieves depending on the value of $K$. Consider the two extreme values: when $K=1$, $T_K$ consists of the single most frequent substring of $S$ (thus $L_K=1$), whose frequency $\tau_K$ can be as large as $\Theta(n)$: in this case, both the construction time and the size of USI$_{TOP-K}$ are $O(n)$, but queries require $\Theta(m+n)$ time, which is impractical as $n$ can be huge. When $K=n^2$, the output of top-$K$ consists of all the substrings of $S$, thus $L_K=n$ and $\tau_K=1$, implying fast $O(m)$-time queries but $O(n^2)$ construction time and size, which is also clearly impractical. Let us now consider $K = \Theta(n)$ (for instance, $K = \frac{n}{100}$). This is arguably the most interesting case in practice: indeed, in this case, the size and construction space of USI$_{TOP-K}$ are $O(n)$, and we can expect both $\tau_K$ and $L_K$ to be small.<fnref n="1" /> In Section IX, we confirm this intuition using several datasets with different characteristics.

**High-Level Idea.** USI$_{TOP-K}$ encodes the global utility of the substrings of $S$ storing them in two different indexes depending on whether they are in $T_K$ or not. The data structure consists of two indexes (a hash table $H$ and the suffix tree $ST(S)$) and of an array PSW of length $n$. We assume the leaves of $ST(S)$ are stored as an array: by definition, this array is equal to $SA(S)$. The hash table $H$ stores the precomputed global utilities of the top-$K$ frequent substrings: a fingerprint of each such substring is added to $H$ as a key, and the value is its global utility. The array PSW implements the prefix-sums strategy discussed in Section I and stores the *local* utility of each prefix of $S$: $\text{PSW}[i] = u(0, i+1)$, for each $i \in [0, n-1]$.

To answer a query for a pattern $P$ of length $m$, we first compute its fingerprint in $O(m)$ time and look it up as a key in $H$: if we find it, the query can be answered in $O(1)$ time simply returning the associated value. If $P$ is not found in $H$ (thus its frequency is bounded by $\tau_K$), then its global utility is computed on the fly using PSW and $ST(S)$. We next provide the details of how USI$_{TOP-K}$ is constructed and how queries are answered within the bounds claimed in Theorem 1.

**Construction.** There are three phases in the construction process: (i) compute the top-$K$ frequent substrings; (ii) compute the global utility of these substrings and add them into the hash table $H$; and (iii) construct $ST(S)$ and PSW.

**Phase (i).** We compute the set $T_K$ of top-$K$ frequent substrings using a data structure that will be described in

Section V. This data structure returns these substrings as a set of triplets $\langle \text{lcp}, \text{lb}, \text{rb} \rangle$, where lcp is the length of the substring and $SA[\text{lb}..\text{rb}]$ is the interval of $SA(S)$ containing all the occurrences of the substring. Equipped with this information, we can thus populate the hash table $H$ as follows.

**Phase (ii).** We first group the substrings of $T_K$ according to their length. To do this, we radix sort the tuples from Phase (i) according to their lcp value $\ell$. We obtain $L_K$ groups of tuples, each for a distinct value $\ell$. For group $\ell$, we use an auxiliary bit vector $B_\ell$ with $n$ entries: its $i$th entry is 1 if and only if a substring of length $\ell$ in the current group occurs at position $S[i]$ (this information is stored in the SA interval $[\text{lb}, \text{rb}]$ of the tuples from the group), and 0 otherwise. We then slide a window of size $\ell$ over $S$. For each starting position $i \in [0, n-\ell]$ of the window, we compute the KR fingerprint of $S[i..i+\ell-1]$ and its local utility $u(i, \ell)$ in $O(1)$ time [18]. We then check if $B_\ell[i] = 1$. If this is the case, we use the fingerprint as a key in $H$ and we aggregate $u(i, \ell)$ with the current value according to function $U$ (if no such key is found in $H$, we create a new entry and initialize its value with $u(i, \ell)$). If $B_\ell[i] = 0$, we do nothing and slide the window to the next position. When the window reaches the end of $S$, we have computed the global utilities of all the top-$K$ frequent substrings of length $\ell$ and stored them in $H$ in $O(n)$ time. We then proceed accordingly to process the next group.

**Phase (iii).** We construct $ST(S)$ [16] and PSW. For the latter, we use a single scan through $S$ and $w$, exploiting the sliding-window property of the local utility function.<fnref n="2" />

**Analysis.** Let us start with the construction time. For Phase (i), we apply the algorithm in Section V, which requires $O(n+K)$ time. For Phase (ii), observe that for any fixed $\ell$, the total number of occurrences of all substrings of length $\ell$ is bounded by $n$. This is because no two distinct substrings of the same length can occur at the same position in $S$. For each $\ell$, we store the occurrences of the top-$K$ frequent substrings of length $\ell$ in a bit vector with $n$ entries. Using a sliding window $S[i..i+\ell-1]$, for all $i \in [0, n-\ell]$, we compute each KR fingerprint in $O(1)$ time [18] and each local utility in $O(1)$ time, and by looking up the fingerprints in the hash table $H$, we aggregate the global utility of all length-$\ell$ substring in $O(n)$ overall time. The total time for processing all $L_K$ lengths is thus $O(nL_K)$. Phase (iii) requires $O(n)$ time. The total construction time is thus bounded by $O(nL_K+K) = O(nL_K)$ as $K = O(nL_K)$.

The construction space is bounded by the $O(n)$ space required to construct $ST(S)$ and PSW, in addition to the space $O(n+K)$ required to construct and store $T_K$ (see Section V). The total space occupied by USI$_{TOP-K}$ (i.e., its final size) is $O(n+K)$, as we have one entry of $H$ for each top-$K$ frequent substring, and both $ST(S)$ and PSW occupy $O(n)$ space.

**Query.** Consider a query pattern $P$ of length $m$. We first compute its KR fingerprint in $O(m)$ time [18] and search it as a key in $H$ to check if $U(P)$ has been precomputed. If so, then the answer to the query is the value stored in

<footnote n="1">¹For instance, in random strings, the length of the longest repeating substring is $O(\log n)$ w.h.p. [31], implying $L_K = O(\log n)$ and $\tau_K = O(1)$.</footnote>

<footnote n="2">²Recall the property from Section III. E.g., if the local utility function $u$ is the sum, $\text{PSW}[i] = \text{PSW}[i-1] + w[i]$, for all $i \in [1, n-1]$.</footnote>
$H$, returned in $O(1)$ time. Consider now the case where the fingerprint is not found in $H$. To compute $U(P)$, we first locate its set $\mathbf{occ}_S(P)$ of occurrences in $S$ using $\mathrm{ST}(S)$ in $O(m + |\mathbf{occ}_S(P)|)$ time [16]. We then retrieve the local utility $u(i, m)$ of each occurrence $i \in \mathbf{occ}_S(P)$ in $O(1)$ time from $\mathrm{PSW}[i+m-1]$ and $\mathrm{PSW}[i-1]$ exploiting the sliding-window property of $u$. Aggregating all such values, we compute and return $U(P)$. Observe that, since we defined $\tau_K$ as the smallest support of any top-$K$ frequent substring, any $P$ that is not in $T_K$ occurs at most $\tau_K$ times, therefore the querying takes $m + |\mathbf{occ}_S(P)| = O(m + \tau_K)$ time.

Combining the last bound with the bounds proved in the Analysis section, we have proved Theorem 1.

## V. TOP-$K$ FREQUENT SUBSTRINGS & USI$_{TOP-K}$ TUNING

In this section, we present a linear-space data structure for performing the following tasks that are necessary for USI:

i. Compute a representation of the top-$K$ frequent substrings of $S$ used in USI$_{TOP-K}$ as a set of triplets.

ii. Estimate the query and construction time of USI$_{TOP-K}$ before constructing it when a user has a value for $K$, and thus knows the size $O(n+K)$ of USI$_{TOP-K}$.

iii. Estimate the size and construction time of USI$_{TOP-K}$ before constructing it when a user has a value for $\tau$, and thus knows the query time $O(m+\tau)$ of USI$_{TOP-K}$.

Let us explain why such a data structure is useful in light of Theorem 1. Consider task (iii) that uses a value of $\tau$ to infer the number $K_\tau$ of $\tau$-frequent substrings of $S$, which determines the size and construction time of USI$_{TOP-K}$. Space-efficient hash tables usually come with some guarantees: e.g., if we are storing $K$ w-bit keys, then the total space usage should be $(1+\epsilon)wK$ bits for some small $\epsilon$ [32]. Thus by computing $K_\tau$, we can estimate the size of our hash table and from thereon, since we also know $n$, the total size of USI$_{TOP-K}$ [33].

**Construction.** The data structure comprises of the suffix tree $\mathrm{ST}(S)$ and of 3 arrays of size at most $n$. The first is an array $\mathcal{T}$ of triplets $\langle v, f(v), q(v) \rangle$, sorted in decreasing order w.r.t. $f(v)$, where $v$ is an explicit node in $\mathrm{ST}(S)$ with frequency $f(v)$ and there are $q(v)$ letters labeling the edge between $v$ and its parent. Each such letter represents a distinct substring of $S$ having the same frequency $f(v)$. The second and third arrays are parallel to $\mathcal{T}$: $Q$ is such that $Q[i] = \sum_{j=1}^i q(v_j)$ is equal to the total number of distinct substrings represented by the first $i$ triplets of $\mathcal{T}$; $\mathcal{L}$ is such that $\mathcal{L}[i]$ is the total number of distinct lengths of the substrings represented by the same triplets. The data structure size is thus $O(n)$.

To construct the data structure, we first construct $\mathrm{ST}(S)$. Values $q(v)$ can be computed for all explicit nodes $v$ with a traversal of $\mathrm{ST}(S)$ by subtracting the string depth $\mathrm{sd}(p(v))$ of the parent $p(v)$ of $v$ from $\mathrm{sd}(v)$. Values $f(v)$ can be computed with a bottom-up tree traversal. As we traverse $\mathrm{ST}(S)$, we extract all triplets $\langle v, f(v), q(v) \rangle$. We then radix sort them in decreasing order of their values $f(v)$, breaking ties so that a triplet $\langle v_i, f(v_i), q(v_i) \rangle$ precedes $\langle v_j, f(v_j), q(v_j) \rangle$ with $f(v_i) = f(v_j)$ if $\mathrm{sd}(v_i) \le \mathrm{sd}(v_j)$: in other words, for equal

frequency, triplets representing shorter substrings precede the triplets representing longer ones. Values $\mathrm{sd}(v_i)$ can be read directly from $\mathrm{ST}(S)$. We store the sorted sequence in $\mathcal{T}$.

To compute $Q$, we scan $\mathcal{T}$ from left to right and progressively sum up the values $q(v)$ from the triplets. To compute $\mathcal{L}$, we consider the triplets of $\mathcal{T}$ one by one from left to right, maintaining a counter $c$ of the distinct lengths and the current maximal string depth $M$. When reading the leftmost triplet $\langle v_1, f(v_1), q(v_1) \rangle$, we set $c = M = \mathcal{L}[1] = \mathrm{sd}(v_1)$. When processing a triplet $\langle v_i, f(v_i), q(v_i) \rangle$, $i > 1$, we first compare $\mathrm{sd}(v_i)$ with the current value of $M$. If $\mathrm{sd}(v_i) > M$, we set $M = \mathrm{sd}(v_i)$, increase $c$ by $\mathrm{sd}(v_i) - M$, and store the new value of $c$ into $\mathcal{L}[i]$. Otherwise, we move on to the next triplet. This is correct because the only distinct lengths that have not been accounted for before the $i$th triplet are the ones longer than $M$. Since $\mathrm{ST}(S)$ has exactly $n$ leaves, it has fewer than $n$ explicit nodes, thus the length of $\mathcal{T}$, $Q$, and $\mathcal{L}$ is bounded by $n$, and values $f(v)$ are also bounded by $n$. This implies that the triplets can be radix sorted in $O(n)$ time and $\mathcal{T}$, $Q$, and $\mathcal{L}$ can be computed in $O(n)$ time. $\mathrm{ST}(S)$ can also be constructed in $O(n)$ time [16], thus the whole construction requires $O(n)$ time. The space is also bounded analogously by $O(n)$.

**Task (i).** We scan $\mathcal{T}$ from left to right, i.e., for decreasing values $f(v)$. For each triplet $\langle v, f(v), q(v) \rangle$, we list all the substrings represented by the implicit nodes on the edge between the parent $p(v)$ of $v$ and $v$, terminating the scan of $\mathcal{T}$ when $K$ substrings have been listed. We represent each listed substring as a different kind of triplet: $\langle \mathrm{lcp}, \mathrm{lb}, \mathrm{rb} \rangle$. From any triplet $\langle v, f(v), q(v) \rangle$, we list $q(v)$ distinct output triplets. Consider the output triplet corresponding to the $\ell$th letter (i.e., implicit node) on the edge from $p(v)$ to $v$. The value $\mathrm{lcp} = \mathrm{sd}(p(v)) + \ell$ is the substring length; $\mathrm{lb}$ and $\mathrm{rb}$ are the endpoints of the interval of leaves descending from $v$. All such intervals can be computed in $O(n)$ time with a traversal of $\mathrm{ST}(S)$. Note that values $\mathrm{lb}$ and $\mathrm{rb}$ are the same for all the output triplets computed for implicit nodes on the same edge.

This procedure is called **Exact-Top-$K$** and requires $O(n+K)$ time. We have arrived at Theorem 2.

**Theorem 2.** For any string of length $n$ and any integer $K > 0$, Exact-Top-$K$ solves TOP-$K$-SUB in $O(n+K)$ time.

The output triplets of **Exact-Top-$K$** are given as input to the construction algorithm of USI$_{TOP-K}$. Each such triplet can be converted to an explicit top-$K$ frequent substring $S[\mathrm{SA}[\mathrm{lb}]..\mathrm{SA}[\mathrm{lb}]+\mathrm{lcp}-1]$ of $S$ should one require the top-$K$ frequent substrings in an explicit form.

**T ask (ii).** Given any $K$ value, we seek to compute the minimum frequency $\tau_K$ of any top-$K$ frequent substring of $S$ and the number $L_K$ of their distinct lengths. This is because $\tau_K$ directly determines the query time of USI$_{TOP-K}$, and $L_K$ its construction time (see Theorem 1). To do this, we binary search for $K$ in $Q$ to find the smallest index $i$ such that $Q[i] \ge K$ (the values of $Q$ are increasing from left to right). Let $T[i] = \langle v_i, f(v_i), q(v_i) \rangle$: then by construction $\tau_K = f(v_i)$ and $L_K = \mathcal{L}[i]$. Since the length of $Q$ is bounded by $n$, the whole process requires $O(\log n)$ time.
**Task (iii).** Given any $\tau$ value, we seek to compute the number $K_\tau$ of $\tau$-frequent substrings of $S$ and the number $L_\tau$ of distinct lengths of all substrings with frequency at least $\tau$. This is because $K_\tau$ and $L_\tau$ directly determine the space occupied by $USI_{\text{TOP-K}}$ and its construction time (see Theorem 1). To do this, we binary search for $\tau$ in the values $f(v)$ of the triplets of $\mathcal{T}$ ($\mathcal{T}$ is sorted in decreasing order of $f(v)$) to find the largest index $i$ such that $f(v_i) \ge \tau$. Then, by construction, we have $K_\tau = \mathcal{Q}[i]$ and $L_\tau = \mathcal{L}[i]$. Since the length of $\mathcal{T}$ is bounded by $n$, the whole process requires $\mathcal{O}(\log n)$ time.

In Section VI, we present an approximate, space-efficient algorithm for Task (i) alternative to the exact one above.

## VI. ESTIMATING TOP-$K$ IN SMALL SPACE

We present **Approximate-Top-$K$**, an algorithm for *estimating* the set of top-$K$ frequent substrings in small space.

**High-Level Idea.** Approximate-Top-$K$ employs sampling and indexing data structures that need small space. It uses a user-defined parameter $s \in [1, n]$, which trades time efficiency (and accuracy) for space, and executes $s$ rounds of sampling. In Round $i \in [0, s)$, it performs the following steps:

1) Samples positions $i+r \cdot s$ of $S$, for each $r \in [0, \lfloor n/s \rfloor]$.

2) Constructs a *sparse* index only for the suffixes starting at the sampled positions.

3) Finds the $K$ substrings which occur the most at the sampled positions (i.e., top-$K$ frequent in the sample).

4) Merges the set of substrings found in Step 3 with those found until Round $i-1$ (if any).

After all rounds of sampling, the algorithm returns the set of substrings that are constructed in Step 4. Note that this approach does not always produce the true set $T_K$ of top-$K$ frequent substrings of $S$ because, by design, the frequency of a substring in $T_K$ may be computed incorrectly if this substring is not part of the top-$K$ frequent substrings in at least one sample. However, the error in the frequencies is one-sided: the frequencies reported by **Approximate-Top-K** lower bound the true frequencies of the output substrings, thus no frequency is over-estimated. In addition, the following bounds hold.

**Theorem 3.** For any string $S$ of length $n$, any integer $K > 0$, and any parameter $s \in [1, n]$, Algorithm **Approximate-Top-K** takes $\tilde{O}(n + sK)$ time and the extra space on top of the space needed by $S$ is $\mathcal{O}(n/s + K)$.

Let us look at the two extremes: when $s=1$, we have one sample and so the algorithm is essentially the same as the one in Section V that uses $\mathcal{O}(n+K)$ extra space, $\mathcal{O}(n+K)$ time, and is *exact*; when $s = \Theta(n)$, we have $\Theta(n)$ samples, the algorithm takes $\mathcal{O}(K)$ extra space, $\tilde{\mathcal{O}}(nK)$ time, and the estimation will be most probably very bad. In practice, we set $s$ to a small function of $n$, such as $\mathcal{O}(\log n)$. This results in sublinear extra space, a reasonable running time, and high accuracy, as we will show later in Section IX.

Note that, although **Approximate-Top-K** works for any $K > 0$, it makes sense to use it when $K < n$, as otherwise

one can simply use **Exact-Top-K** that takes $\mathcal{O}(n+K)$ time using $\mathcal{O}(n)$ extra space.

**Details.** As a preprocessing step, we construct on $S$ the in-place *Longest Common Extension* (LCE) data structure of Prezza [34] in $\mathcal{O}(n)$ time and $\mathcal{O}(1)$ extra space. This data structure answers LCE queries on $S$ in $\mathcal{O}(\text{polylog}(n))$ time: given two integers $i, j \in [0, n)$, the LCE query asks for the length of the longest common prefix of $S[i..n-1]$ and $S[j..n-1]$. This data structure will efficiently implement the string comparison functions used in Steps 2 to 4. After each Round $i$, we store the set of the top-$K$ frequent substrings as a set of tuples $(j, \ell, f_{[0,i]})$: $S[j..j+\ell-1]$ is a witness occurrence for substring $U = S[j..j+\ell-1]$; and $f_{[0,i]}$ is the total estimated frequency of $U$ in Rounds $0, \dots, i$. Step 1 is straightforward. The next steps are provided below.

**Step 2.** At any round $i$, we construct an index consisting of the sparse suffix array $SSA_i$ [35] and the sparse LCP array $SLCP_i$ [35] for the sampled positions. $SSA_i$ consists of the lexicographically sorted sequence of the suffixes of $S$ starting at the sampled positions. To construct it, we use in-place mergesort [36], where any two substrings can be compared in $\mathcal{O}(\text{polylog}(n))$ time by finding the length *lce* of their longest common prefix with the LCE data structure of Prezza [34], and comparing the letters at position *lce* + 1 in each substring. Therefore, lexicographically sorting the $\lfloor n/s \rfloor$ sampled suffixes via in-place mergesort requires $\tilde{\mathcal{O}}(n/s)$ time and no extra space. To construct $SLCP_i$, we then compute the length of the longest common prefix of every two consecutive entries of $SSA_i$, again using $\mathcal{O}(\text{polylog}(n))$-time LCE queries. This procedure thus requires $\tilde{\mathcal{O}}(n/s)$ time per round.

**Step 3.** To compute the top-$K$ frequent substrings from $SSA_i$ and $SLCP_i$, we apply the algorithm of Abouelhoda et al. [37, Algorithm 4.4], which simulates a bottom-up traversal of the compacted trie of the suffixes in $SSA_i$ (note that, for using this algorithm, we do not need to construct such a trie). This traversal requires $\mathcal{O}(n/s)$ time and produces one tuple $(\text{lcp}, \text{lb}, \text{rb}, \text{childList})$ per explicit node $v$ of the trie: $\text{lcp} = |\text{str}(v)|$ is the string depth of node $v$, i.e., the length of the substring represented by node $v$ in the trie; $[\text{lb}, \text{rb}]$ encodes all suffixes $SSA_i[\text{lb}..\text{rb}]$ in $SSA_i$ with $\text{str}(v)$ as prefix, thus $\text{rb}-\text{lb}+1$ is the frequency of $\text{str}(v)$ in the sample; and, finally, `childList` is a list storing the children of node $v$ in the trie. These $\mathcal{O}(n/s)$ tuples have the same role as the tuples used in Task (i) of Section V, and we can sort them in ascending order of $\text{rb}-\text{lb}+1$ (i.e., by frequency) in linear time using radix sort. This is because any frequency is at most $n/s$, the maximal number of suffixes in Round $i$. Listing the top-$K$ frequent substrings of the $i$th round, similarly to Task (i) of Section V, takes $\tilde{\mathcal{O}}(n/s+K)$ time. Each substring $U$ in the list is represented by a tuple $(j, \ell, f_{[i,i]})$: $S[j..j+\ell-1]$ is a witness occurrence for $U$ and $f_{[i,i]} = \text{rb}-\text{lb}+1$ is its frequency in the $i$th sample.

**Step 4.** We efficiently merge the list of the top-$K$ frequent substrings found in Rounds $0, \dots, i-1$ with the list of the top-$K$ frequent substrings computed in Step 3 of Round $i$, and only keep the top-$K$ frequent substrings in the merged
list. The merged list consists of the union of the substrings
appearing in either list: the frequency of a substring in the
merged list is given by the sum of its frequency in each of the
two original lists. To produce the merged list, we thus need to
efficiently find out which substrings appear in both lists to sum
their frequencies. To do so, we concatenate the list of $K$ tuples
$\langle j, \ell, f_{[0,i-1]} \rangle$ produced by Step 4 of Round $i-1$ with the list
of $K$ tuples $\langle j, \ell, f_{[i,i]} \rangle$ produced by Step 3 of Round $i$ and sort
the resulting list in lexicographic order of the substrings rep-
resented by the tuples using in-place mergesort [36], similarly
to Step 2. We then scan this sorted list: substrings appearing
in both lists will be represented by adjacent tuples, thus we
can sum up their frequencies to produce the new estimated
frequencies $f_{[0,i]}$ in total $\tilde{O}(K)$ time and no extra space. Once
we have produced the merged list, we sort it again, this time in
decreasing order of the frequencies $f_{[0,i]}$, using another round
of mergesort. We finally output the first $K$ tuples $\langle j, \ell, f_{[0,i]} \rangle$
of this sorted list, representing the top-$K$ frequent substrings
found until Round $i$. We have arrived at Theorem 3.

**A Space-Efficient Construction Algorithm for USI<sub>TOP-K</sub>.**
Approximate-Top-*K* can be employed in the construction of USI<sub>TOP-*K*</sub> instead of Exact-Top-*K* to make it more space-efficient. However, the worst-case query time of this space-efficient version of USI<sub>TOP-*K*</sub> is no longer O(*m*+*τ*<sub>*K*</sub>): indeed, since the output of Approximate-Top-*K* is not exact, we can no longer guarantee that *τ*<sub>*K*</sub> bounds the frequency of any substring whose global utility is not stored in the hash table *H*. This implies that, in the worst case, the query time can be O(*n*). However, in Section IX, we show that queries are much faster in practice and competitive to the exact counterpart.

As for the construction of this space-efficient data struc-
ture, we can use the sliding-window approach described in
Section IV. The total construction time is $\tilde{O}(nL_k + sK)$:
$\tilde{O}(n+sK)$ time to run **Approximate-Top-K** plus $O(nL_K)$ to
construct the data structure with the sliding-window procedure.
Although asymptotically the construction space of this space-
efficient data structure is $O(n+K)$, thus the same as for
USI$_{TOP-K}$, in practice it is determined by the space needed
by **Approximate-Top-K**, which is significantly lower than that
of **Exact-Top-K** (see Section IX).

VII. WHY NOT MODIFYING A FREQUENT ITEM MINING ALGORITHM?

Assume we have a stream of *N* items. Demaine et al. [38] proved that for any *N* and *K*, a one-pass deterministic algorithm storing at most *K* items may fail to identify the top-*K* most frequent items in certain sequences (this is related to [21]). Thus, approximate streaming algorithms for the top-*K* most frequent items have been proposed [23], [21], [22].

We consider a variation to the task of estimating the top-*K*
most frequent items. We treat the stream as our string *S* of
length *n* = *N*, where letters are streamed one by one, and
we aim to identify the top-*K* most frequent substrings of *S*.
Thus, we must consider not only single letters (items) *S*[*i*], but
whole substrings *S*[*i*..*i* + *ℓ* − 1], for any length *ℓ* > 1. While

there may be O(N²) distinct substrings, the problem can be
solved exactly using *N* counters by means of the suffix tree,
which can be built online, one letter at a time [39]: indeed,
for *K* ≥ *N*, the suffix tree provides an exact solution.

We now consider whether a solution exists for $K < N$. For $K \le |\Sigma|$, an exact solution is not possible, as implied by [38]. In the remaining case $|\Sigma| < K < N$, we are not aware of an exact solution, but we can discuss two approximate solutions, which are from the literature and can fail in estimating the top-$K$ most frequent substrings when using $K$ counters: (1) **SubstringHK**, an adaptation of **HeavyKeeper** [24] to substrings of a single string $S$ (**HeavyKeeper** is the state of the art for computing the top-$K$ frequent strings in a database of several strings); and (2) **Top-$K$ Trie** [25], which implements a variant of the Misra-Gries algorithm to approximately find the top-$K$ frequent substrings of $S$. We note that both solutions fail due to the extension from *items* to *substrings* in $S$ of the Misra-Gries/Space-Saving scheme with $K$ counters.

**SubstringHK.** The strategy in [24] combines the count-all and admit-all-count-some methods for strings and relies on a CM sketch-like structure [23] with exponential decay and on a summary ssummary which tracks the frequency of *K* strings for fast queries. We adapt it to substrings from *S* with this rule: for any *i*, try to insert *S*[*i*] into ssummary, and then try to insert *S*[*i*..*i* + *ℓ*], *ℓ* ≥ 1, only if *S*[*i*..*i* + *ℓ* − 1] is in ssummary. A string is successfully inserted into ssummary if its estimated frequency, stored in the CM sketch table, is larger than the frequency of a string in ssummary, or if the latter contains fewer than *K* strings. Here, the frequency value of a string is the number of times it has been a candidate for insertion into ssummary. To hash substrings we use KR fingerprints [18] and pay O(1) time per substring; hence, for a total number *z* of hashed substrings, this requires O(*z*) time and O(*K*) space. On average, *z* is linear in *n*, since the probability of extending the next letter of the current length-*ℓ* substring is programmatically chosen to be 1/c*ℓ* for a constant *c* > 1, which implies expected O(1) time per letter. SubstringHK can fail for, say, *S* = (AB)*n*/² where *n*/² ≥ *K* > 4, *K* is even, and |Σ| = 2. In this example, SubstringHK fails to report half of the output. The details are deferred to [40].

**Top-$K$ Trie.** The authors of [25] introduced Top-$K$ Trie, a novel trie data structure that approximately maintains the top-$K$ most frequent substrings in $S$ in $O(K)$ space, and reports them in $O(n+K)$ time. Just as SubstringHK, it can fail to report half of the output. The details are deferred to [40].

VIII. RELATED WORK

There are many works for mining utility-oriented item-
sets [41], association rules [42], and episodes [43], [44], [45].
Unlike set-valued data, strings with utilities have duplicate
elements and the order of the elements is crucial. Unlike
event sequences, strings with utilities have no specific temporal
information, and thus the notion of time window is irrelevant.
Thus, mining strings with utilities requires specialized algo-
rithms (e.g., [8]).
<table><caption>TABLE II: Dataset properties and values of parameters. The default values are in bold. M stands for millions.</caption><thead><tr><th>Dataset</th><th>Length<br>n</th><th>Alphabet<br>size σ</th><th>Number of top-K<br> frequent substrings K</th><th>Number of sampling<br>rounds s</th></tr></thead><tbody><tr><td>ADV [26]</td><td>2.19 · 10<sup>5</sup></td><td>14</td><td>[2K, 6K] (6K)</td><td>6</td></tr><tr><td>IoT [51]</td><td>1.9 · 10<sup>7</sup></td><td>63</td><td>[0.0225M,0.36M] (0.18M)</td><td>[10, 80] (20)</td></tr><tr><td>XML [53]</td><td>2 · 10<sup>5</sup></td><td>95</td><td>[0.2M, 3M] (2M)</td><td>[4, 80] (6)</td></tr><tr><td>HUM [20]</td><td>2.9 · 10<sup>9</sup></td><td>4</td><td>[3.6M, 58M] (29M)</td><td>[4, 80] (6)</td></tr><tr><td>ECOLI [52]</td><td>4.6 · 10<sup>9</sup></td><td>4</td><td>[15M, 75M] (45M)</td><td>[4, 80] (8)</td></tr></tbody></table>

Recently, two algorithms for mining utility-oriented substrings were proposed in [8]. Both take $O(n \log n)$ time but one of them offers drastic space savings in practice when, in addition, a lower bound on the length of the output strings is provided as input. There are also algorithms that are applied to a collection of short strings comprised of letters or itemsets [2], [3], [4]. These algorithms mine subsequences. Our work differs from the aforementioned works in that it focuses on query answering and in that it uses different utility functions.

Our approach includes finding top-K frequent substrings. Thus, it is related to the literature on top-K pattern mining. There are works for mining top-K frequent patterns (e.g., frequent itemsets [46], [47] and closed frequent itemsets [46]) or association rules [48] from set-valued data, and works for mining top-K patterns from sequential data (e.g., sequential patterns [49] and closed sequential patterns [50]). These are not alternatives to our approach, as they mine different types of patterns than substrings. The most relevant to our work are algorithms for estimating the top-K most frequent items in a stream (e.g., [24], [25]). As discussed in Section VII and will be experimentally shown in Section IX, these algorithms cannot be suitably adapted to mine top-K frequent substrings.

# IX. EXPERIMENTAL EVALUATION

## A. Data and Environment

**Data.** We used 5 real datasets of sizes up to 4.6 billion letters; see Table II for their characteristics. These include the ADV dataset from Section II, in which every advertisement is associated with a real CTR value. The strings IoT [51] and ECOLI [52] are also associated with real utilities. In IoT, the utilities are RSSIs (Received Signal Strength Indicators representing signal strength values of sensors) normalized in [0, 1], and in ECOLI, confidence scores [5] in [0, 1]; see Section I. In XML [53] and HUM [20], there are no real utilities. Thus, we selected each utility $w[i]$, for all $i \in [0, n)$, uniformly at random from $\{0.7, 0.75, \dots, 1\}$ as in [8].

**Environment.** All experiments were conducted on an AMD EPYC 7282 CPU with 256 GB RAM. All methods were implemented in C++. The source code is available at https://github.com/chenhuiping/Utility-Oriented-String-Indexing.

## B. Top-K Frequent Substring Mining

**Methods.** We compared our Exact-Top-K (ET) and Approximate-Top-K (AT) algorithms to SubstringHK (SH) and Top-K Trie (TT) from Section VII. The default values for K in ET and for K and s in AT are in Table II. The range of s values is in $O(\log n)$, as discussed in Section VI.

**Measures.** Let $T_K$ be the set of top-K frequent substrings and $T'_K$ that of the substrings found by an algorithm that estimates

$T_K$. We used Accuracy, defined as the percentage of substrings in $T'_K$ with the same frequency as those in $T_K$, Relative Error (RE), defined as $\frac{\sum_{P \in T_K} |occ_S(P)| - \sum_{P' \in T'_K} |occ_S(P')|}{\sum_{P \in T_K} |occ_S(P)|}$, and Normalized Discounted Cumulative Gain (NDCG) [54] using the frequencies of the substrings in $T_K$ in Ideal DCG and those of the substrings in $T'_K$ in DCG. These quantify the efficiency loss of an algorithm that estimates $T_K$ by $T'_K$ when answering queries with a frequency smaller than those in $T_K$. Effectiveness. Figs. 3a to 3e show the effectiveness of AT, TT and SH in terms of Accuracy, for varying K; we do not report any results for ET as it is exact. We also omit the results for SH when it did not finish within 5 days. AT is remarkably accurate for all K values, unlike TT and SH. For example, the Accuracy of AT was 94.9% on average and at least 76.5%, while that of TT (respectively, SH) is 25.7% (respectively, 44.3%) on average and at least 0.15% (respectively, 6.9%). TT and SH perform the worst on the IoT dataset because they miss long frequent substrings (see Section VII). For example, the longest string among the exact top-(22500) frequent substrings has length 11816, while the longest among the top-(22500) found by TT and SH has length 546 and 1577, respectively.

Figs. 3f to 3i show the effectiveness of AT, TT, and SH in terms of Accuracy, for varying n; the result for ADV is analogous (omitted). AT was highly accurate (e.g., its Accuracy was 94.1% on average and at least 80%). As expected, the effectiveness of AT increases with n (e.g., in Fig. 3f it increased from 93.6% to 99.9% as n increased from $3.7 \cdot 10^6$ to $18.7 \cdot 10^6$). This is because s is the same for all n values and thus more positions of the text are sampled as n increases. TT and SH performed much worse than AT, for the same reasons as before. For example, SH outperformed TT but its average Accuracy was only 50.6%, and it did not terminate within 5 days in Fig. 3i when $n \ge 2754 \cdot 10^6$.

Figs. 3j, 4a, 4b, and 4c show the impact of s in AT on Accuracy. As expected (see Section VI), a smaller s makes AT more accurate and $s = O(\log n)$ is reasonable ($\log n$ is 25, 28, 32, and 33 for IoT, XML, HUM, and ECOLI, respectively).

Fig. 4d shows the NDCG values for all datasets. The results are analogous to those reported for Accuracy. In fact, AT achieved a result very close to the optimal (i.e., NDCG scores at least 0.9993), outperforming both TT and SH. In the IoT dataset, the difference from TT (respectively, SH) was more than 93% (respectively, 70%). Fig. 4e shows the impact of s in AT on NDCG; the values decrease with s but very slightly and are at least 0.993.

The results with respect to the RE measure are analogous to those of Accuracy, so we omitted all RE results.

**Space.** We report results for XML and HUM; the results for the other datasets are analogous. Figs. 5a and 5b show the impact of n on space. The space for both ET and AT increases linearly with n, in line with their space complexities. AT takes 4.5 times less space than ET on average, and TT takes the least space. The space of TT and SH does not depend on n, in line with their $O(K)$ space complexity. Figs. 5c and 5d show the impact of s on the space consumption of AT. As expected by
<figure><img src="image_3.png" /><figcaption>Fig. 3: Accuracy vs (a-e) *K*, (f-i) *n*, and (j) *s* (*s* affects only *AT*). We omit *SH* when it did not terminate within 5 days.</figcaption></figure>

<figure><img src="image_4.png" /><figcaption>Fig. 4: Accuracy vs (a-c) *s*. NDCG (d) for all datasets and (e) vs *s*. We omit *SH* when it did not terminate within 5 days.</figcaption></figure>

<figure><img src="image_5.png" /><figcaption>Fig. 5: Space for ET, AT, TT, and SH vs (a, b) *n* and (c, d) *s* (recall that parameter *s* affects only *AT*). Runtime for ET, AT, TT, and SH (e, f) *K*, (g, h) *n*, and (i, j) *s*. We omit *SH* when it did not terminate within 5 days.</figcaption></figure>

its space complexity, *AT* requires less space as *s* increases, which together with its very high effectiveness highlights the benefit of our sampling approach.

**Runtime.** We report results for XML and HUM; the results for the other datasets are analogous. Figs. 5e and 5f show the impact of *K* on the runtime, which is small for all algorithms except *SH*. This is because *K* for ET and TT, or *sK* for *AT* in their time complexities is smaller than *n*. *SH* takes much more time as *K* increases because *z* gets larger (see Section VII). *TT* is the fastest, *ET* is slightly slower, *AT* is even slower, and *SH* is the slowest. Figs. 5g and 5h show that all algorithms scale with *n* as predicted by their time complexities. Again, *ET* is faster than *AT* by more than one order of magnitude, *TT* is the fastest, and *SH* is faster than *AT* in XML but slower in the larger HUM dataset. Figs. 5i and 5j show that *AT* takes less time as *s* increases. This is because, in general, constructing

*many small* tries of total size *n* is faster than constructing *few larger* tries of total size *n*. Indeed, the former computation is performed when *s* is larger.

### C. Useful String Indexing

**Methods.** We refer to the USI<sub>TOP-<i>K</i></sub> data structure constructed based on the ET algorithm (see Section V) as UET and to that based on the *AT* algorithm (see Section VI) as UAT. We compared these approaches to four nontrivial baselines, as no existing method can be used as a competitor. All baselines employ the suffix array *SA*(*S*) for query answering and the PSW array (see Section IV) for storing the local utility of each prefix of *S*, but they differ in the type of queries that they may “cache” (i.e., answer without using *SA*(*S*)).

1) BSL1 (No Query Caching). This is the baseline from subsection “Why is USI Challenging?” in Section I. It
<figure><img src="image_6.png" /><figcaption>Fig. 6: UET, UAT, and BSL1, ..., BSL4: Average query time vs (a-e) *K* and (f-j) *p*. Index size vs (k-m) *K* and (n-p) *n*. Construction time vs (q, r) *K* and (s, t) *n*.</figcaption></figure>

answers all queries with SA(*S*) and PSW.

2) BSL2 (Least Recently Used (LRU)). This is similar to UET, but in the hash table *H* it stores at most *K* precomputed global utilities of the top-*K* most recently queried substrings, instead of the utilities of the top-*K* frequent substrings. Like UET, if the queried pattern is not in *H*, it uses SA(*S*) and PSW to compute *U*(*P*).

3) BSL3 (Top-*K* Seen-so-far). This baseline is similar to BSL2, except that it replaces the least *frequently* queried substring in *H*, instead of the least recently queried. The frequencies are maintained using an auxiliary data structure which offers the functionality of a min-heap on substring frequency and of a hash table like *H* in BSL2.

4) BSL4 (Space-efficient Top-*K* Seen-so-far). BSL4 differs from BSL3 in that its auxiliary data structure uses the functionality of a count-min-sketch (as in [24]) instead of that of a hash table for space efficiency.

BSL1-4 differ from UET and UAT in that they cache different types of queries and do not have query time guarantees.

Without the loss of generality, we employed the commonly-used [1] "sum of sums" global utility function: $U(P) = \sum_{i \in \text{occ}_S(P)} u(i, |P|)$, where $u(i, |P|) = \sum_{k \in [i, i+|P|-1]} w[k]$, for $i \in [0, n - |P|]$, and $u = 0$ otherwise.

**Parameters.** We configured ET and AT, used in UET and UAT, respectively, using the default *K* and *s* values (see

Table II). We used two types of query workloads per dataset, $W_1$ and $W_{2,p}$ (the role of *p* will be explained next). Each workload has 0.7, 6, 40, 70 and 0.1, million query patterns, for the IoT, XML, HUM, ECOLI and ADV dataset, respectively; more queries for larger datasets. To construct $W_1$, we: (1) selected 90% of the query patterns from the top-$\frac{n}{50}$ (respectively, top-$\frac{n}{60}$) frequent substrings of the input dataset when using the IoT, XML, HUM or ADV dataset (respectively, the ECOLI dataset), and (2) selected the remaining query patterns randomly from either the previously selected frequent substrings, or from substrings of the input dataset that have length randomly selected in [1, 5000] for all datasets except IoT and ADV. For IoT, we used [1, 20000] (as its frequent substrings are longer), and for ADV, we used a range of [3, 200] (as it has a small length). To construct $W_{2,p}$, we selected *p*% of the queries randomly from the top-$\frac{n}{100}$ frequent substrings, and the remaining queries as in $W_1$. We constructed a workload $W_{2,p}$ for each $p \in \{20, 40, 60, 80\}$ per dataset. In short, our query workloads ensure that there are queries of frequent substrings and/or queries appearing multiple times.

**Measures.** We used all 4 relevant measures of efficiency [55]: (1) query time, (2) index size, (3) construction time, and (4) construction space. For (1) and (3), we used the **chrono C++** library. For (2), we used the **mallinfo2 C++** function. For (4), we recorded the maximum resident set size using the
/usr/bin/time -v command. We do not report construction space results here, as they are essentially the same as those in Section IX-B: the top-$K$ frequent substring mining determines the construction space of both UET and UAT.

**Overview.** We show that UET and UAT: (1) have query times up to 15 times faster than those of the fastest baseline; (2) have size similar to that of the baselines; and (3) take more time to be constructed than the baselines, but scale linearly or near-linearly with the input string length $n$.

**Query Time.** Figs. 6a to 6e show the average query time for the queries in the workloads of type $W_1$, for varying $K$. Note that, for all tested $K$ values, both UET and UAT are on average 3.1 and up to 15 times faster than the fastest baseline, BSL3. The query time of our data structures decreases with $K$, as more queries are answered efficiently using the hash table; this is more obvious in Fig. 6d where more queries are answered. On the contrary, the query time of the baselines stays the same or decreases much more slowly. This directly shows the benefit of efficiently answering query patterns that occur frequently in string $S$, unlike “caching” different types of queries as the baselines do. Among our approaches, UAT is slightly slower but takes smaller space to construct (recall that the construction space is determined by AT).

Figs. 6f to 6j show the average query time for the queries in workload $W_{2,p}$, for varying $p \in \{20, 40, 60, 80\}$. Both UET and UAT outperform all baselines (e.g., the best baseline is slower than our slower approach, UAT, by 199% on average). Also, UET and UAT become much faster with $p$, as more queries are answered by their hash table, unlike the baselines. **Index Size.** We report results for XML, HUM, and ADV; the results for the other datasets are analogous. Figs. 6k to 6m show the index size of all approaches for varying $K$. The index sizes are similar (e.g., in Fig. 6l they differ by less than 3GB's or less than 4%), since most of the space is occupied by the suffix array $SA(S)$. BSL1 has a slightly smaller index size than others, as it does not have a hash table, while that of BSL4 is slightly smaller than BSL3 due to the use of the sketch in BSL4. Figs. 6n to 6p show the index size of all approaches for varying $n$. All approaches scale linearly with $n$, as expected by their space complexities, and take roughly the same space for the same reasons as in the last experiment.

**Construction Time.** We report results for XML and HUM; the results for the other datasets are analogous. Figs. 6q and 6r show that the baselines need less time to be constructed than UET and UAT and that UET is constructed faster than UAT. This is because: (1) the construction for the baselines is much simpler than that of UET and UAT, and (2) the construction time of UAT has an extra term $\tilde{O}(n + sK)$ and $sK = \tilde{O}(n)$ in our setting. Figs. 6s and 6t show the construction time for varying $n$. All approaches scale linearly or near-linearly in line with their time complexities. Again, the baselines outperform our approaches and UET takes less time than UAT.

# X. FUTURE WORK

There are three directions for future work. First, it would be worthwhile to employ machine learning to define utility

functions based on interestingness measures [56] or to speed up search based on the underlying data distribution [57]. Second, it would be practically useful to investigate how to set the construction parameters $K$ and $\tau$. Our data structure from Section V allows us to produce a large number of $(K, \tau)$ values *efficiently*, which could be then used to select a good trade-off [58]. Third, it is interesting to investigate a dynamic version of USI. We next present a partial solution for the case where *only letter appends are allowed* [39].

We assume that we have constructed the index for $S$. We maintain two auxiliary dynamic data structures: a heap storing the frequencies of the explicit nodes of $ST(S)$; and a table storing the KR fingerprints of all prefixes of $S$. Assume a new letter $\alpha$ is appended to $S$ creating $S' = S\alpha$. We extend PSW by one position, storing the sum of the utility of $\alpha$ and the former last entry of PSW; and we update $ST(S)$ by Ukkonen's algorithm [39] adding a new branching node and a leaf. The frequency of the new leaf is trivially 1, and that of the new branching node is $g+1$, where $g$ and 1 are the frequencies of its two children: the previously existing child and the new leaf. At this point, we insert the frequencies of these two new nodes in the heap and increment the frequencies of all ancestors of the new branching node by one. Incrementing these frequencies is challenging as *there could be many such ancestors*. We then traverse the heap to list the top-$K$ frequent substrings in $S'$.

We next compute the KR fingerprint of each top-$K$ substring using the KR fingerprints table [59]. Consider a substring $s$, occurring at position $i$ of $S'$, which is in the top-$k$ frequent substrings of $S'$ but not of $S$. We observe that $s$ must be a suffix of $S'$: this is because the frequencies increase monotonically with appending. We compute the local utility $u(i, |s|)$ of $s$ using the updated PSW and do the following:

* If $s$ is in $H$, we add $u(i, |s|)$ to its previous global utility.

* If $s$ is not in $H$ (it is new), it must have frequency at most $\tau_K + 1$ in $S'$. We access its locus in $ST(S')$, compute its global utility $U(s)$ in $S'$, and add it to $H$. Thus we may spend $O(\tau_K)$ time for each of the $O(K)$ substrings.

Finally, we delete any entry in $H$ that does not represent a top-$K$ frequent substring in $S'$. Querying is not affected as all data structures needed for querying are updated.

Unfortunately, as highlighted above, maintaining the node frequencies in $ST(S')$ and adding the new global utilities in $H$ dynamically can in general be very costly. We thus defer the investigation of this dynamic version of USI to future work.

# ACKNOWLEDGMENTS

This work was supported by PANGAIA and ALPACA projects funded by the EU under MCSA Grant Agreements 872539 and 956229; by the Next Generation EU PNRR MUR M4 C2 Inv 1.5 project ECS00000017 Tuscany Health Ecosystem Spoke 6 CUP B63C2200068007 and I53C22000780001; by the MUR PRIN 2022 YRB97K PINC; and by the Institute for Interdisciplinary Data Science and Artificial Intelligence Pump Prime Funding at the University of Birmingham.
REFERENCES

[1] W. Gan, J. C. Lin, P. Fournier-Viger, H. Chao, V. S. Tseng, and P. S. Yu, “A survey of utility-oriented pattern mining,” *IEEE Trans. Knowl. Data Eng.*, vol. 33, no. 4, pp. 1306–1327, 2021.

[2] J. Yin, Z. Zheng, and L. Cao, “Uspan: an efficient algorithm for mining high utility sequential patterns,” in *The 18th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, KDD ’12, Beijing, China, August 12-16, 2012* (Q. Yang, D. Agarwal, and J. Pei, eds.), pp. 660–668, ACM, 2012.

[3] O. K. Alkan and P. Karagoz, “Crom and huspext: Improving efficiency of high utility sequential pattern extraction,” *IEEE Trans. Knowl. Data Eng.*, vol. 27, no. 10, pp. 2645–2657, 2015.

[4] W. Gan, J. C. Lin, J. Zhang, H. Chao, H. Fujita, and P. S. Yu, “Proum: Projection-based utility mining on sequence data,” *Inf. Sci.*, vol. 513, pp. 222–240, 2020.

[5] B. Ewing, L. Hillier, M. C. Wendl, and P. Green, “Base-calling of automated sequencer traces using phred. i. accuracy assessment,” *Gen. Res.*, vol. 8, pp. 175–185, 1998.

[6] A. Vlavianos, L. K. Law, I. Broustis, S. V. Krishnamurthy, and M. Faloutsos, “Assessing link quality in IEEE 802.11 wireless networks: Which is the right metric?,” in *Proceedings of the IEEE 19th International Symposium on Personal, Indoor and Mobile Radio Communications, PIMRC 2008, 15-18 September 2008, Cannes, France*, pp. 1–6, IEEE, 2008.

[7] P. W. Farris, N. T. Bendle, P. E. Pfeifer, and D. J. Reibstein, *Marketing Metrics*. Wharton School Publishing, 2nd ed., 2010.

[8] G. Bernardini, H. Chen, A. Conte, R. Grossi, V. Guerrini, G. Loukides, N. Pisanti, and S. P. Pissis, “Utility-oriented string mining,” in *Proceedings of the 2024 SIAM International Conference on Data Mining, SDM 2024, Houston, TX, USA, April 18-20, 2024* (S. Shekhar, V. Papalexis, J. Gao, Z. Jiang, and M. Riondato, eds.), pp. 190–198, SIAM, 2024.

[9] S. Tang, “Robust advertisement allocation,” in *Proceedings of the Twenty-Sixth International Joint Conference on Artificial Intelligence, IJCAI 2017, Melbourne, Australia, August 19-25, 2017* (C. Sierra, ed.), pp. 4419–4425, ijcai.org, 2017.

[10] C. F. Ahmed, S. K. Tanbeer, and B. Jeong, “Mining high utility web access sequences in dynamic web log data,” in *11th ACIS International Conference on Software Engineering, Artificial Intelligences, Networking and Parallel/Distributed Computing, SNPD 2010, London, England, UK, June 9-11, 2010* (J. Ma, L. Bacon, W. Du, and M. Petridis, eds.), pp. 76–81, IEEE Computer Society, 2010.

[11] C. Zhang, Z. Du, W. Gan, and P. S. Yu, “TKUS: mining top-k high utility sequential patterns,” *Inf. Sci.*, vol. 570, pp. 342–359, 2021.

[12] J. C. Lin, Y. Djenouri, G. Srivastava, Y. Li, and P. S. Yu, “Scalable mining of high-utility sequential patterns with three-tier mapreduce model,” *ACM Trans. Knowl. Discov. Data*, vol. 16, no. 3, pp. 60:1–60:26, 2022.

[13] S. C. Manekar and S. R. Sathe, “A benchmark study of k-mer counting methods for high-throughput sequencing,” *GigaScience*, vol. 7, p. giy125, 10 2018.

[14] F. Constantin, C. Harris, S. Jeong, A. Mehta, and X. Tan, “Optimizing ad refresh in mobile app advertising,” in *Proceedings of the 2018 World Wide Web Conference on World Wide Web, WWW 2018, Lyon, France, April 23-27, 2018* (P. Champin, F. Gandon, M. Lalmas, and P. G. Ipeirotis, eds.), pp. 1399–1408, ACM, 2018.

[15] C. I. Ezeife and Y. Lu, “Mining web log sequential patterns with position coded pre-order linked wap-tree,” *Data Min. Knowl. Discov.*, vol. 10, no. 1, pp. 5–38, 2005.

[16] M. Farach, “Optimal suffix tree construction with large alphabets,” in *38th Annual Symposium on Foundations of Computer Science, FOCS ’97, Miami Beach, Florida, USA, October 19-22, 1997*, pp. 137–143, IEEE Computer Society, 1997.

[17] U. Manber and E. W. Myers, “Suffix arrays: A new method for on-line string searches,” *SIAM J. Comput.*, vol. 22, no. 5, pp. 935–948, 1993.

[18] R. M. Karp and M. O. Rabin, “Efficient randomized pattern-matching algorithms,” *IBM J. Res. Dev.*, vol. 31, no. 2, pp. 249–260, 1987.

[19] M. Kokot, M. Dlugosz, and S. Deorowicz, “KMC 3: counting and manipulating k-mer statistics,” *Bioinform.*, vol. 33, no. 17, pp. 2759–2761, 2017.

[20] https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_000001405.26/.

[21] J. Misra and D. Gries, “Finding repeated elements,” *Sci. Comput. Program.*, vol. 2, no. 2, pp. 143–152, 1982.

[22] A. Metwally, D. Agrawal, and A. E. Abbadi, “Efficient computation of frequent and top-k elements in data streams,” in *Database Theory - ICDT 2005, 10th International Conference, Edinburgh, UK, January 5-7, 2005, Proceedings* (T. Eiter and L. Libkin, eds.), vol. 3363 of *Lecture Notes in Computer Science*, pp. 398–412, Springer, 2005.

[23] G. Cormode and S. M. Muthukrishnan, “Approximating data with the count-min sketch,” *IEEE Softw.*, vol. 29, no. 1, pp. 64–69, 2012.

[24] T. Yang, H. Zhang, J. Li, J. Gong, S. Uhlig, S. Chen, and X. Li, “Heavykeeper: An accurate algorithm for finding top-k elephant flows,” *IEEE/ACM Trans. Netw.*, vol. 27, no. 5, pp. 1845–1858, 2019.

[25] P. Dinklage, J. Fischer, and N. Prezza, “Top-k frequent patterns in streams and parameterized-space LZ compression,” in *22nd International Symposium on Experimental Algorithms, SEA 2024, July 23-26, 2024, Vienna, Austria* (L. Liberti, ed.), vol. 301 of *LIPICS*, pp. 9:1–9:20, Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2024.

[26] https://bit.ly/45z4wvr.

[27] https://keywordclustering.zenbrief.com.

[28] https://ur0.jp/5dkt.

[29] M. Crochemore, C. Hancart, and T. Lecroq, *Algorithms on strings*. Cambridge University Press, 2007.

[30] T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park, “Linear-time longest-common-prefix computation in suffix arrays and its applications,” in *Combinatorial Pattern Matching, 12th Annual Symposium, CPM 2001 Jerusalem, Israel, July 1-4, 2001 Proceedings* (A. Amir and G. M. Landau, eds.), vol. 2089 of *Lecture Notes in Computer Science*, pp. 181–192, Springer, 2001.

[31] B. Bollobás and S. Letzter, “Longest common extension,” *Eur. J. Comb.*, vol. 68, pp. 242–248, 2018.

[32] M. A. Bender, A. Conway, M. Farach-Colton, W. Kuszmaul, and G. Tagliavini, “Iceberg hashing: Optimizing many hash-table criteria at once,” *J. ACM*, vol. 70, no. 6, pp. 40:1–40:51, 2023.

[33] S. Kurtz, “Reducing the space requirement of suffix trees,” *Softw. Pract. Exp.*, vol. 29, no. 13, pp. 1149–1171, 1999.

[34] N. Prezza, “Optimal substring equality queries with applications to sparse text indexing,” *ACM Trans. Algorithms*, vol. 17, no. 1, pp. 7:1–7:23, 2021.

[35] J. Kärkkäinen and E. Ukkonen, “Sparse suffix trees,” in *Computing and Combinatorics, Second Annual International Conference, COCOON ’96, Hong Kong, June 17-19, 1996, Proceedings* (J. Cai and C. K. Wong, eds.), vol. 1090 of *Lecture Notes in Computer Science*, pp. 219–230, Springer, 1996.

[36] J. Katajainen, T. Pasanen, and J. Teuhola, “Practical in-place mergesort,” *Nord. J. Comput.*, vol. 3, no. 1, pp. 27–40, 1996.

[37] M. I. Abouelhoda, S. Kurtz, and E. Ohlebusch, “Replacing suffix trees with enhanced suffix arrays,” *J. Discrete Algorithms*, vol. 2, no. 1, pp. 53–86, 2004.

[38] E. D. Demaine, A. López-Ortiz, and J. I. Munro, “Frequency estimation of internet packet streams with limited space,” in *Algorithms - ESA 2002, 10th Annual European Symposium, Rome, Italy, September 17-21, 2002, Proceedings* (R. H. Möhring and R. Raman, eds.), vol. 2461 of *Lecture Notes in Computer Science*, pp. 348–360, Springer, 2002.

[39] E. Ukkonen, “On-line construction of suffix trees,” *Algorithmica*, vol. 14, no. 3, pp. 249–260, 1995.

[40] *Supplemental Material*. https://github.com/chenhuiping/Utility-Oriented-String-Indexing/blob/main/Supplement.pdf.

[41] C. F. Ahmed, S. K. Tanbeer, B. Jeong, and Y. Lee, “Efficient tree structures for high utility pattern mining in incremental databases,” *IEEE Trans. Knowl. Data Eng.*, vol. 21, no. 12, pp. 1708–1721, 2009.

[42] Y. Shen, Z. Zhang, and Q. Yang, “Objective-oriented utility-based association mining,” in *Proceedings of the 2002 IEEE International Conference on Data Mining (ICDM 2002), 9-12 December 2002, Maebashi City, Japan*, pp. 426–433, IEEE Computer Society, 2002.

[43] C. Wu, Y. Lin, P. S. Yu, and V. S. Tseng, “Mining high utility episodes in complex event sequences,” in *The 19th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, KDD 2013, Chicago, IL, USA, August 11-14, 2013* (I. S. Dhillon, Y. Koren, R. Ghani, T. E. Senator, P. Bradley, R. Parekh, J. He, R. L. Grossman, and R. Uthurusamy, eds.), pp. 536–544, ACM, 2013.

[44] W. Gan, J. C. Lin, H. Chao, and P. S. Yu, “Discovering high utility episodes in sequences,” *IEEE Trans. Artif. Intell.*, vol. 4, no. 3, pp. 473–486, 2023.

[45] L. Wan, L. Chen, and C. Zhang, “Mining dependent frequent serial episodes from uncertain sequence data,” in *2013 IEEE 13th International Conference on Data Mining, Dallas, TX, USA, December 7-10, 2013*
(H. Xiong, G. Karypis, B. Thuraisingham, D. J. Cook, and X. Wu, eds.), pp. 1211–1216, IEEE Computer Society, 2013.

[46] K. Chuang, J. Huang, and M. Chen, "Mining top-k frequent patterns in the presence of the memory constraint," *VLDB J.*, vol. 17, no. 5, pp. 1321–1344, 2008.

[47] R. C. Wong and A. W. Fu, "Mining top-K frequent itemsets from data streams," *Data Min. Knowl. Discov.*, vol. 13, no. 2, pp. 193–217, 2006.

[48] M. Riondato and E. Upfal, "Efficient discovery of association rules and frequent itemsets through sampling with tight performance guarantees," *ACM Trans. Knowl. Discov. Data*, vol. 8, no. 4, pp. 20:1–20:32, 2014.

[49] F. Petitjean, T. Li, N. Tatti, and G. I. Webb, "Skopus: Mining top-k sequential patterns under leverage," *Data Min. Knowl. Discov.*, vol. 30, no. 5, pp. 1086–1111, 2016.

[50] P. Tzvetkov, X. Yan, and J. Han, "TSP: mining top-k closed sequential patterns," *Knowl. Inf. Syst.*, vol. 7, no. 4, pp. 438–457, 2005.

[51] IoT dataset. https://bit.ly/3X3rpmE.

[52] Ecoli dataset. https://bit.ly/3pcU0d4.

[53] XML dataset. http://pizzachili.dcc.uchile.cl/texts.html.

[54] K. Järvelin and J. Kekäläinen, "Cumulated gain-based evaluation of IR techniques," *ACM Trans. Inf. Syst.*, vol. 20, no. 4, pp. 422–446, 2002.

[55] L. A. K. Ayad, G. Loukides, and S. P. Pissis, "Text indexing for long patterns: Anchors are all you need," *Proc. VLDB Endow.*, vol. 16, no. 9, pp. 2117–2131, 2023.

[56] M. Baena-García and R. M. Bueno, "Mining interestingness measures for string pattern mining," *Knowl. Based Syst.*, vol. 25, no. 1, pp. 45–50, 2012.

[57] D. Ho, S. Kalikar, S. Misra, J. Ding, V. Md, N. Tatbul, H. Li, and T. Kraska, "LISA: Learned indexes for sequence analysis," *bioRxiv*, 2021.

[58] S. Börzsönyi, D. Kossmann, and K. Stocker, "The skyline operator," in *Proceedings of the 17th International Conference on Data Engineering, April 2-6, 2001, Heidelberg, Germany* (D. Georgakopoulos and A. Buchmann, eds.), pp. 421–430, IEEE Computer Society, 2001.

[59] T. I. J. Kärkkäinen, and D. Kempa, "Faster sparse suffix sorting," in *31st International Symposium on Theoretical Aspects of Computer Science (STACS 2014), STACS 2014, March 5-8, 2014, Lyon, France* (E. W. Mayr and N. Portier, eds.), vol. 25 of *LIPIcs*, pp. 386–396, Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2014.