Sorted Consecutive Occurrence Queries in Substrings
Abstract
The string indexing problem is a fundamental computational problem with numerous applications, including information retrieval and bioinformatics. It aims to efficiently solve the pattern matching problem: given a text of length for preprocessing and a pattern of length as a query, the goal is to report all occurrences of as substrings of . Navarro and Thankachan [CPM 2015, Theor. Comput. Sci. 2016] introduced a variant of this problem called the gap-bounded consecutive occurrence query, which reports pairs of consecutive occurrences of in such that their gaps (i.e., the distances between them) lie within a query-specified range . Recently, Bille et al. [FSTTCS 2020, Theor. Comput. Sci. 2022] proposed the top- close consecutive occurrence query, which reports the closest consecutive occurrences of in , sorted in non-decreasing order of distance. Both problems are optimally solved in query time with -space data structures.
In this paper, we generalize these problems to the range query model, which focuses only on occurrences of in a specified substring of . Our contributions are as follows:
-
We propose an -space data structure that answers the range top- consecutive occurrence query in time.
-
We propose an -space data structure that answers the range gap-bounded consecutive occurrence query in time, where is a positive constant and denotes the number of outputs.
Additionally, as by-products, we present algorithms for geometric problems involving weighted horizontal segments in a 2D plane, which are of independent interest.
Keywords and phrases:
string algorithm, consecutive occurrences, suffix treeFunding:
Takuya Mieno: JSPS KAKENHI Grant Number JP24K20734.Copyright and License:
2012 ACM Subject Classification:
Mathematics of computing Combinatorial algorithmsAcknowledgements:
We sincerely thank the anonymous referees for their thorough review and valuable feedback, which have contributed to enhancing the clarity and quality of this paper. The first author extends his heartfelt gratitude to his thesis supervisor, Prof. Sanjeev Saxena, for his invaluable guidance and unwavering support throughout this work.Editors:
Paola Bonizzoni and Veli MäkinenSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
The string indexing problem involves constructing a data structure that efficiently supports pattern matching queries. Given a text of length and a pattern of length , the goal is to report all occurrences of as substrings of . This problem has numerous applications in the real world including information retrieval and bioinformatics. A typical example of such an index structure is the suffix tree [37], a compact trie of all suffixes of . When combined with perfect hashing (e.g., [16, 32]), a suffix tree provides an -space data structure that answers pattern matching queries in optimal time for given pattern , where is the number of occurrences of in .
In this work, we focus on variants of pattern matching queries that consider the distances between the starting positions of every two occurrences of in . Keller et al. [23] introduced a non-overlapping pattern matching problem, which reports only occurrences of separated by at least characters. They proposed a data structure of size that reports the maximal sequence of non-overlapping occurrences of in sorted in textual order, in query time where is the output size. Cohen and Porat [12] later improved the query time to . Several subsequent studies extended their work [17, 22, 20].
In 2016, Navarro and Thankachan [28] introduced another new variant of the pattern matching query called the consecutive occurrence query. The query reports consecutive occurrences of pattern , where each pair of occurrences has no other occurrences of between them and the distance is within range specified by a query. They designed an -space data structure that supports the consecutive occurrence query in optimal time. Subsequently, Bille et al. [7] considered the top- close consecutive occurrence query, which reports (at most) consecutive occurrences of in non-decreasing order of distance, where is specified in a query. They proposed an -space data structure that answers the top- consecutive occurrence query in optimal time. In the same work, they also presented two other trade-offs for the problem, each using space, with query times of either or . Recently, Akram and Saxena [2] revisited Bille et al.’s work and proposed a simpler data structure with the same time/space bounds, which is the basis of our proposed method in this paper. Further, Bille et al. [8] addressed an extension of the query that requires consecutive occurrences of two (possibly distinct) patterns and where their distances lie within range . They showed that the query can be answered in time with space, and that any data structure using space requires query time unless the String SetDisjointness Conjecture [21] fails. More recently, Gawrychowski, Gourdel, Starikovskaya and Steiner considered consecutive occurrence problems on grammar-compressed texts [18, 19]. As we have mentioned, the consecutive occurrence queries has attracted significant attention in recent years.
In this paper, we consider each variant of consecutive occurrence queries defined in [7] and [28] within substrings specified by queries. The first one is the range top- consecutive occurrence query that reports the closest consecutive occurrences of pattern in substring , sorted by distance, where the query input consists of pattern , range , and integer . The second one is the range gap-bounded consecutive occurrence query that reports all the consecutive occurrences of pattern in substring where their distances lie within , where the query input consists of pattern , range representing the substring of , and gap range . The formal definitions of the problems are provided in Section 2. Our main results are as follows:
-
For the range top- consecutive occurrence query, we propose an -size data structure with a query time of (Theorem 12).
-
For the range gap-bounded consecutive occurrence query, we propose an -size data structure with a query time , where is a positive constant (Theorem 15).
Both of the data structures consist of the suffix tree [37] of and some appropriately chosen geometric data structures, associated with heavy paths [36] of the suffix tree. Although the high-level idea is similar to that of [28], we carefully employ non-trivial combinations of data structures since our problems only require occurrences within the query substring and outputs needs to be sorted by distance unlike [28]. Additionally, as by-products, we develop algorithms for geometric problems involving weighted horizontal segments in 2D plane, which are of independent interest.
Related Work
Variants of range queries (a.k.a. internal or substring queries) have been proposed for various problems in string processing. Mäkinen and Navarro [26] proposed a data structure for a fundamental range query called the position-restricted substring searching query, which reports the occurrences of pattern within a specified substring . Their solution requires space, and answers queries in time. Keller et al. [23] introduced the range non-overlapping pattern matching query and proposed a data structure of size that can answer queries in time. Cohen and Porat [12] later improved these results to space and query time. Crochemore et al. [14] proposed an alternative trade-off with space and query time.
Bille and Gørtz [6] showed that several string problems, including the position-restricted substring searching query, can be reduced to the substring range reporting problem, and provided an efficient solution for the problem. One of the results from [6] is a data structure of size that answers the position-restricted substring searching query in optimal time, which is an improvement of Mäkinen and Navarro’s result [26]. Range queries have been considered not only for finding patterns in strings but also for computing regularities in strings or compressing substrings (see [13, 24, 15, 1, 3, 4, 27, 35, 25] and references therein).
Given a set of horizontal segments in the plane, the orthogonal segment intersection problem involves designing an efficient data structure that can be used to find the segments intersected by a vertical query segment. Chazelle [10] presented a solution that occupies space and takes time to answer a query, where is the output size. It is an important problem in computational geometry and has been studied in various settings (see [31, 33, 34]).
Rahul and Janardan [31] studied a variant of the orthogonal segments intersection problem where the input set consists of weighted horizontal segments and queries to be answered are of the following type: given a vertical segment and an integer , report the segments intersected by the query segment with largest weights. They proposed a general technique to solve top- variants of geometric problems efficiently, and solve this problem using space and query time.
2 Preliminaries
2.1 Notations
Let be an ordered alphabet. An element in is called a character. An element in is called a string. The length of a string is denoted by . The empty string is the string of length . If holds for strings , and , then , and are called a prefix, a substring, and a suffix of , respectively. They are called a proper prefix, a proper substring, and a proper suffix of if , , and , respectively. For a string and an integer with , we denote by the th character of . Also, for integers with , we denote by the substring of that starts at position and ends at position . For convenience, we define if . We sometimes use notation for suffixes. For strings and , we denote by the set of starting positions of occurrences of in . For two positions with , the pair is called a consecutive occurrence of in if there is no element with . For a consecutive occurrence we call the value the distance of . We denote by the set of consecutive occurrences of in . Note that if .
Now we formally define two problems we tackle in this paper.
Definition 1 (Top- query).
The range top- consecutive occurrence query over string is, given a query where is a pattern and are integers, to output the top- close consecutive occurrences , sorted in non-decreasing order of distance.
Definition 2 (Gap-bounded query).
The range gap-bounded consecutive occurrence query over string is, given a query where is a pattern and are integers, to output the consecutive occurrences with , sorted in non-decreasing order of distance.
We give a concrete example for the top- query in Figure 1.
In what follows, we fix a string of length arbitrarily. In this paper, we assume the standard word-RAM model with word size .
2.2 Algorithmic Tools
Suffix Trees
The suffix tree of string is a compacted trie for the set of suffixes of [37]. We denote by the path-string obtained by concatenating the edge labels from the root to node of the suffix tree of . If the last character of is unique (i.e., occurs in only once), then the suffix tree of has exactly leaves and there is a one-to-one correspondence between the leaves and the suffixes of . More precisely, for each suffix of , there exists a leaf of the suffix tree of such that , and vice versa. Thus, we label such a leaf with integer . For a substring of , we define as the highest node of the suffix tree of such that is a prefix of the string .
The suffix tree of string over can be constructed in time [37].
In the rest of this paper, we assume that the last character of is unique (one can achieve this property by appending a new letter), and we denote by the suffix tree of . Namely, has exactly leaves.
Heavy Path Decomposition of Tree
A heavy path of a tree is a root-to-leaf path in which each node has a size no smaller than the size of any of its siblings (the size of a node is the number of nodes in the subtree rooted at that node). Heavy path decomposition is a process of decomposing a tree into heavy paths [36]. First, we find a heavy path by starting from the tree’s root and choosing a child with the maximum size at each level. We follow the same procedure recursively for each subtree rooted at a node that is not on the heavy path, but its parent node is (on the heavy path). As a result, a collection of (disjoint) heavy paths is obtained. Some of its properties are:
-
each node belongs to exactly one heavy path,
-
any path from the root to a leaf can pass through at most heavy paths where is the size of the number of nodes in the tree,
-
the number of heavy paths equals the number of leaves in the tree.
All heavy paths of a rooted tree with nodes can be computed in time [36].
Segment Tree
The segment tree [5] is an important data structure in computational geometry. It stores a set of line segments in the plane such that the segments intersected by a vertical query line can be computed in time, where is the number of reported segments. It can be built in space and time. It is a balanced binary search tree of height built over the -coordinates of the segments’ endpoints. Each node stores a vertical slab and a set of segments, where and are real numbers. Let be the list of leaf nodes in the left-to-right order. The slab of a leaf node , for each , is determined by the key values of and , and the vertical slab of an internal node is the union of those of its children. Note that the vertical slabs of the nodes of any particular level form a partition of the plane. A segment is stored at each highest node such that and no endpoint of lies inside . Given a real value , the path from the root to the leaf whose vertical slab contains is referred to as the search path for . An important property of the segment tree is that a segment intersects the vertical line through if and only if it is stored at some node of the search path for .
Fractional Cascading Technique
Chazelle and Guibas [11] introduced the fractional cascading technique, a data structure technique which is useful in the scenarios where one needs to search an item in multiple sorted lists. It speeds up the search process. We briefly describe the idea of the technique in the context where lists are associated with the nodes of a balanced binary tree, the reader may refer to [11] for full details. Let be a balanced binary tree with height, and each node stores a sorted list of comparable items where is the combined size of all lists. Given a root-to-leaf path in , one can trivially find the position (rank) of an item in the list of each node on the path in time; performing a binary search at each node of the path. By employing fractional cascading technique, the search time can be reduced to . The technique introduces an augmented list for each node in the tree: the augmented list consists of the items of and every fourth item from the list of each child; the list is also sorted. These augmented lists are built in a bottom-up fashion. Each item in stores a constant amount of information: (1) whether is from or from one of ’s children, (2) pointers to immediate neighbors of on either side in that belong to , (3) a pointer to the appropriate item in for each child of . If the position of in is known, one can find its position in the list of either child (of node ) in time using the saved pointers. Suppose we are to find the position (rank) of an item in lists of nodes on a particular root-to-leaf path . A binary search is used to find the location of in (and hence in ). Then, using the pointers stored in , the correct rank of in the list of the next node on the path can be computed in time. Generally speaking, if the rank of in is known, the rank of in can be obtained in time using the pointers stored in . Thus, the total time spent would be .
Sorted Orthogonal Range Reporting Queries
A sorted range reporting problem over an array of integers is, given a query where are integers, to report the smallest values in sub-array in sorted order. The following result is due to Brodal et al. [9].
Lemma 3 ([9]).
There is a data structure of size that can answer any sorted range reporting query in time. The data structure can be constructed in time.
A 2D orthogonal range reporting problem asks to represent a set of 2D planar points into an efficient data structure such that all the points inside an orthogonal query rectangle can be reported efficiently. Nekrich and Navarro [29] studied a variant of the problem where the output points are to be reported in increasing (or decreasing) order of one of the two coordinates. They proposed an almost space solution to the problem that takes time to answer a query, where is the size of the input set and is the number of reported points. The output points are reported one by one in the sorted order. Their main result is as follows.
Lemma 4 (Theorem 2 in [29]).
Given a set of points in the plane with integer coordinates, one can preprocess the set so that the points lying inside a query rectangle can be reported in sorted order in time, where is output size. The space used by the data structure is .
Dynamic Fusion Nodes
A dynamic fusion node [30] is a data structure for a dynamic set of integers which supports operations on the set including insertion, deletion, predecessor, and successor. Every query can be executed in time where is the size of the dynamic set and is the machine word size. The data structure uses space. If is close to , the following holds:
Lemma 5 ([30]).
If , we can maintain a dynamic set of integers supporting insertion, deletion, predecessor, and successor in time using space.
We will use this lemma later in the case where .
3 Naïve Solutions
In this section, we present a data structure that answers top- queries in near-optimal time. The data structure also supports gap-bounded queries in the same time bound. However, the space complexity is .
We first build the suffix tree over the text of length . Recall that the labels of leaves in the subtree rooted at a node correspond to the occurrences of . Let denote the set of consecutive occurrences of . For each , we define a -dimensional point . Let be the set of all such -d points at node . We then preprocess the set , for each , into a data structure that supports sorted range reporting queries using Lemma 4. The resulting data structure supports both types of queries.
Firstly, we estimate the space complexity. The size of the set of consecutive occurrences is one less than the number of leaves in the subtree rooted at node . In the worst case (when is left-skewed or right-skewed), the total size of all sets , , is . As the set contains one point for each consecutive occurrence in the set , holds. Consequently, . The suffix tree occupies space. The sorted range reporting structure representing the set uses space due to Lemma 4. Thus, the total space used by the data structures associated with all nodes is . Therefore, the space complexity of the data structure is .
Top- query algorithm for given
We first find the node where the search for pattern in the suffix tree terminates. Then, we find the points of in the rectangle with smallest y-coordinates (i.e., smallest distances) using the range reporting data structure stored at node . Let be the consecutive occurrence corresponding to the (returned) point with the largest x-coordinate. If the copy of starting at index ends with a position greater than , report the remaining consecutive occurrences as output. Otherwise, we report the consecutive occurrences with smallest distances. Finding in the suffix tree takes time. If we are to find points with smallest y-coordinates in sorted order, the structure stored at a node takes time to answer a query. The additional step to scan the returned points and report consecutive occurrences takes time. Thus, the total time needed to answer a top- query is .
Gap-bounded query algorithm for given
For gap-bounded query, the procedure is very similar. Again, we first find the node where the search for in the suffix tree terminates. Then, we query the data structure stored at node with the rectangle . Let be the set of the consecutive occurrences corresponding to the returned points. Finally, we simply scan the set and remove the consecutive occurrence with the largest first occurrence if , in words, the copy of at index does not fit entirely within the index range . The resulting set is our output to the gap-bounded query. The time spent to answer a gap-bounded query is where denotes the number of outputs for the query. The analysis is very similar to that of top- query. Thus, we have the following proposition.
Proposition 6.
Given a given text , one can build an -space index that can be used to answer a top- query or a gap-bounded query in query time.
4 Range Top- Consecutive Occurrence Queries
In this section, we propose an algorithm that solves the top- query using sub-quadratic space. Our approach is similar to those employed in [28, 7]. The suffix tree is decomposed using heavy path decomposition. For each heavy path in the decomposition, we define a set of horizontal segments that compactly represents the sets of consecutive occurrences associated with nodes . We organize these segments into a data structure, denoted by , that supports top- queries for patterns with on the path .
4.1 Solution
Let be the suffix tree built over the text . The tree is decomposed using the heavy path decomposition, which gives disjoint (heavy) paths. Let be a heavy path in the decomposition. We denote by the highest node in the path . We say that a consecutive occurrence is present at node if . The following lemma is helpful in compactly representing the sets of consecutive occurrences.
Lemma 7.
For each consecutive occurrence , there exists two nodes and on the heavy path such that is present at each node of the sub-path of joining and and is not present at any other node of .
Proof.
Let , and suppose is present at node for some . This implies that the leaves and are present in the subtree of rooted at node . As we move down from to , one or both leaves, or , might branch off from the heavy path . If neither leaf nor is present in subtree rooted at , the pair would not be part of the set . Otherwise, would continue to exist at the next node , i.e., . Note that if is not present at , it will not appear in any descendant node of on the path . This is because as we move down the path the existing leaves only disappear. See also Figure 2 for examples.
Since and are two occurrences of , the string must occur at these positions as is a prefix of . If has no occurrence such that , the pair is a consecutive occurrence of , i.e., . Otherwise, there are occurrences between and , and the pair becomes a consecutive occurrence at the highest ancestor of where all occurrences between and disappear (i.e., the corresponding leaves branch off from the heavy path ). Let denote the depth of within heavy path , i.e., and where is the parent of . By Lemma 7, for each consecutive occurrence present at some node of path , there are two nodes and on path such that is present at each node of the path connecting these two nodes. We create a horizontal segment in a 2D grid for each consecutive occurrence and associate as satellite data. Let be the set of all such horizontal segments corresponding to path . By the construction of segments, the pair is a consecutive occurrence of pattern if and only if and hold. Also, since we are only interested in occurrences within substring , we will report such satisfying . Thus, we can obtain the desired top- segments by reporting segments111The reason for finding up to segments is the same as in Section 3. with the smallest y-coordinates such that and hold. Therefore, once , and in are computed, the remaining process of a top- query can be reduced to the following geometric problem for :
Definition 8 (2D top- stabbing query with weight constraint).
A set of horizontal segments in a 2D plane and weight function are given for preprocessing. The query is, given , to report the segments with smallest y-coordinates in non-decreasing order of y-coordinate such that and hold for every segment .
We will later prove the following theorem:
Theorem 9.
There is a data structure of size that can answer the query of Definition 8 in time.
We have the following result regarding the total size of the sets of segments.
Lemma 10 ([7]).
The total number of horizontal segments for all heavy paths is .
By Theorem 9 and Lemma 10, the total size of our data structure is . Since the locus of can be computed in time using the suffix tree, we obtain the following.
Lemma 11.
We can represent a given text into an space data structure that supports a range top- consecutive occurrence query in time.
Note that the query time of the lemma is optimal if . When , the factor dominates the pattern length , and the query time becomes .
Further, we slightly improve the query time using an additional data structure that efficiently answer queries with short patterns, i.e., . For each node with in the suffix tree , we store a data structure built over the set of consecutive occurrences as in Section 3. The additional space used at each node is . In the suffix tree , the total number of leaves in the subtrees rooted at the nodes of a particular level is , so . Hence, the overall space used by the additional data structure is , which is subsumed by .
For a query pattern with , we simply find the node in the suffix tree in time and query the associated range reporting data structure as in the naïve solution of Section 3. Thus, the query time would be . Thus, we obtain the main theorem of this paper:
Theorem 12.
We can represent a given text into an space data structure that supports a range top- consecutive occurrence query in time.
4.2 Proof of Theorem 9: Solving Geometric Subproblem
In this subsection, we prove Theorem 9.
Data Structure
Given set of horizontal segments, we build a segment tree over . Each node maintains the segments stored at node , in a list sorted by their weights. To efficiently perform predecessor search, we employ the fractional cascading technique (see also Section 2) on the sorted lists for all . We define an array over the list such that stores the y-coordinate of segment . We then preprocess the array for the sorted range reporting queries of Lemma 3. The size of the enhanced segment tree structure is since data structures associated with each node use space and holds.
Query Algorithm
Given a query , we first find the search path for in the segment tree . Let . We then traverse the path in the top-down fashion and for each node , compute the positions (ranks) of and in list , respectively denoted by and , using the pointers provided by the fractional cascading technique described in Section 2. We prepare an incremental buffer of size consisting of rows. Each th row of corresponds to the node on the path , denoted by . Moreover, we maintain a min-heap implemented as a dynamic fusion node (Lemma 5). See Figure 3 for illustration.
We find top- (i.e., the smallest) items from the subarrays for all nodes and initialize the heap with the minima. Also, we initialize the counter for each node . We then keep repeating the following steps until the heap gets empty or items are reported:
-
1.
Pop the minimum item from the heap and report it. Let be the node on the path from which the item came.
-
2.
If ’s buffer is non-empty, simply pop the minimum item from and insert it into the heap . Then continue to the next iteration.
-
3.
Otherwise (if is empty), find top- items from by using Lemma 3. Then remove the first half of them, which have already been moved to in previous steps, and insert the remaining items to . Lastly, pop the minimum item from and insert it into the heap , and increment ’s counter by .
Correctness
We focus on the changes to the buffer for any fixed node throughout the query algorithm. Buffer grows only if we enter Step 3, where is empty. Picking up only steps where grows, in each such step, is updated to the top- items from the items in that are not inserted to before, for incremental . Also, when the smallest item from is inserted to at Step 2, the item is removed from . Hence, buffer keeps the top- items from that have not been inserted to for some . Also, the smallest unreported item from is always present in heap for every due to Step 2. Thus, for each iteration of the three steps of the algorithm, the smallest unreported item from that satisfies the weight constraint will be reported at Step 1 of the iteration.
Running Time
We now analyze the running time of the query algorithm. Given , determining the search path in the segment tree takes time. Also, thanks to the fractional cascading technique, all the ranks of and in the nodes in can be computed in a total of time. As the heap is implemented as dynamic fusion node structure, initializing takes time. While iterating the loop, when buffer becomes empty (i.e., all items of have either been moved to or reported as output) for a node , it is replaced by a new buffer twice the size of the previous one in time by Lemma 3. Since (1) the size of is at most the number of items from already reported or moved to and (2) the number of rows in is , the total size of the buffer is . Further, each operation in a dynamic fusion node structure takes constant time. To summarize, the total time spent222Note that if we implement the heap as a standard binary heap instead of the dynamic fusion node, the query time becomes since the size of is . to answer the query is .
We have completed the proof of Theorem 9.
5 Range Gap-Bounded Consecutive Occurrence Queries
In this section, we describe a space efficient data structure that supports gap-bounded queries. The data structure is similar to the one described for top- queries in Section 4, and it uses space. The query time is . The data structure differs from the top- structure (described in Section 4) only in the representation of the sets .
We first build the suffix tree of and decompose it using heavy path decomposition. For each heavy path in the decomposition, we compute a set of horizontal segments that compactly represent the consecutive occurrences as in Section 4.1. Let be a query we should answer. Firstly, we find the heavy path where belongs. Then, we can obtain the desired segments as follows:
-
1.
Compute segments such that , , and hold.
-
2.
Scan the consecutive occurrences corresponding to the obtained segments and remove (at most one) consecutive occurrence with if it exist (as we mentioned in Section 3).
-
3.
Report the remaining segments.
The second and the third steps are obvious. The first step can be reduced to the following problem for , which is different from that of the top- algorithm.
Definition 13 (2D height-bounded stabbing query with weight constraint).
A set of horizontal segments in a 2D plane and weight function are given for preprocessing. The query is, given , to report all the segments in non-decreasing order of y-coordinate such that , and hold for every segment .
We show the following theorem:
Theorem 14.
There is a data structure of size that can answer the query of Definition 13 in time where is a constant and is the number of outputs.
Proof.
The idea is very similar to that of Theorem 9. We construct a segment tree over and associate some data structures with nodes of the tree. Given a query , we first find the search path for . After that, the remaining operations related to and are considered on each node in . The differences are: (1) we associate another data structure with nodes of the segment tree, and (2) we do not need to use a doubling technique with an incremental buffer in the query algorithm. Below, we focus only on the differences from Theorem 9.
Let be a node of the segment tree . For each segment in the set of segments for , we create a 2D point . We then construct a sorted orthogonal range reporting data structure of Lemma 4 on top of the set of points. The total size of the segment tree structure with range reporting structures is .
When a query is given, we traverse the search path for . At each node in , we create a (sorted) list of all the desired segments in by reporting all the points within the rectangle using the sorted orthogonal range reporting data structure. After finishing the traversal, we merge the sorted lists for all by using a heap implemented as dynamic fusion node as in Section 4, and report the segments in the merged list in order. The total time to answer a query is time since the length of is and range reporting query at each takes time.
The correctness can be seen from the definition of the 2D points within each node and the definition of the sorted range reporting query to be performed on those points.
Now we obtain an -query-time method for the range gap-bounded consecutive occurrence query. We reduce the query time to using the same technique employed for the top- case. For each node in the suffix tree with , we build a data structure over the set of consecutive occurrences as in Section 3. By the same arguments used in the top- case, the total space used by these additional data structures is , which is dominated by . Therefore, the next theorem holds;
Theorem 15.
We can represent a given text into an space data structure that supports a range gap-bounded consecutive occurrence query in time.
6 Conclusions
In this paper, we introduced range variants of consecutive occurrence queries, generalizing the problems studied in previous work [28, 7]. Specifically, we proposed:
-
A data structure of size that answers the range top- consecutive occurrence query in time.
-
A data structure of size that answers the range gap-bounded consecutive occurrence query in time, where is a positive constant and denotes the number of outputs.
Further, we presented efficient algorithms for geometric problems involving weighted horizontal segments in a 2D plane, which appeared as sub-problems in our approach and are of independent interest.
Our data structures require space in the worst case, whereas existing solutions for non-range variants use only space. Thus, reducing the space complexity of our data structures is an interesting direction for future research.
References
- [1] Paniz Abedin, Arnab Ganguly, Solon P. Pissis, and Sharma V. Thankachan. Efficient data structures for range shortest unique substring queries. Algorithms, 13(11):276, 2020. doi:10.3390/A13110276.
- [2] Waseem Akram and Sanjeev Saxena. Consecutive occurrences with distance constraints. In Conference on Algorithms and Discrete Applied Mathematics, pages 3–13. Springer, 2024. doi:10.1007/978-3-031-52213-0_1.
- [3] Amihood Amir, Panagiotis Charalampopoulos, Solon P. Pissis, and Jakub Radoszewski. Dynamic and internal longest common substring. Algorithmica, 82(12):3707–3743, 2020. doi:10.1007/S00453-020-00744-0.
- [4] Golnaz Badkobeh, Panagiotis Charalampopoulos, Dmitry Kosolobov, and Solon P. Pissis. Internal shortest absent word queries in constant time and linear space. Theor. Comput. Sci., 922:271–282, 2022. doi:10.1016/J.TCS.2022.04.029.
- [5] Mark de Berg, Otfried Cheong, Marc J. van Kreveld, and Mark H. Overmars. Computational geometry: algorithms and applications, 3rd Edition. Springer, 2008. doi:10.1007/978-3-540-77974-2.
- [6] Philip Bille and Inge Li Gørtz. Substring range reporting. Algorithmica, 69(2):384–396, 2014. doi:10.1007/S00453-012-9733-4.
- [7] Philip Bille, Inge Li Gørtz, Max Rishøj Pedersen, Eva Rotenberg, and Teresa Anna Steiner. String indexing for top-k close consecutive occurrences. Theor. Comput. Sci., 927:133–147, 2022. doi:10.1016/J.TCS.2022.06.004.
- [8] Philip Bille, Inge Li Gørtz, Max Rishøj Pedersen, and Teresa Anna Steiner. Gapped indexing for consecutive occurrences. Algorithmica, 85(4):879–901, 2023. doi:10.1007/S00453-022-01051-6.
- [9] Gerth Stølting Brodal, Rolf Fagerberg, Mark Greve, and Alejandro López-Ortiz. Online sorted range reporting. In Yingfei Dong, Ding-Zhu Du, and Oscar H. Ibarra, editors, Algorithms and Computation, 20th International Symposium, ISAAC 2009, Honolulu, Hawaii, USA, December 16-18, 2009. Proceedings, volume 5878 of Lecture Notes in Computer Science, pages 173–182. Springer, 2009. doi:10.1007/978-3-642-10631-6_19.
- [10] Bernard Chazelle. Filtering search: A new approach to query-answering. SIAM Journal on Computing, 15(3):703–724, 1986. doi:10.1137/0215051.
- [11] Bernard Chazelle and Leonidas Guibas. Fractional cascading: I. a data structuring technique. Algorithmica, 1:133–162, January 1986. doi:10.1007/BF01840440.
- [12] Hagai Cohen and Ely Porat. Range non-overlapping indexing. In Yingfei Dong, Ding-Zhu Du, and Oscar H. Ibarra, editors, Algorithms and Computation, 20th International Symposium, ISAAC 2009, Honolulu, Hawaii, USA, December 16-18, 2009. Proceedings, volume 5878 of Lecture Notes in Computer Science, pages 1044–1053. Springer, 2009. doi:10.1007/978-3-642-10631-6_105.
- [13] Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, and Clifford Stein. Introduction to algorithms. MIT press, 2022. URL: http://mitpress.mit.edu/books/introduction-algorithms.
- [14] Maxime Crochemore, Costas S. Iliopoulos, Marcin Kubica, M. Sohel Rahman, German Tischler, and Tomasz Walen. Improved algorithms for the range next value problem and applications. Theor. Comput. Sci., 434:23–34, 2012. doi:10.1016/J.TCS.2012.02.015.
- [15] Maxime Crochemore, Costas S. Iliopoulos, Jakub Radoszewski, Wojciech Rytter, Juliusz Straszynski, Tomasz Walen, and Wiktor Zuba. Internal quasiperiod queries. In Christina Boucher and Sharma V. Thankachan, editors, String Processing and Information Retrieval - 27th International Symposium, SPIRE 2020, Orlando, FL, USA, October 13-15, 2020, Proceedings, volume 12303 of Lecture Notes in Computer Science, pages 60–75. Springer, 2020. doi:10.1007/978-3-030-59212-7_5.
- [16] Michael L. Fredman, János Komlós, and Endre Szemerédi. Storing a sparse table with O(1) worst case access time. In 23rd Annual Symposium on Foundations of Computer Science, Chicago, Illinois, USA, 3-5 November 1982, pages 165–169. IEEE Computer Society, 1982. doi:10.1109/SFCS.1982.39.
- [17] Arnab Ganguly, Rahul Shah, and Sharma V. Thankachan. Succinct non-overlapping indexing. Algorithmica, 82(1):107–117, 2020. doi:10.1007/S00453-019-00605-5.
- [18] Pawel Gawrychowski, Garance Gourdel, Tatiana Starikovskaya, and Teresa Anna Steiner. Compressed indexing for consecutive occurrences. In Laurent Bulteau and Zsuzsanna Lipták, editors, 34th Annual Symposium on Combinatorial Pattern Matching, CPM 2023, June 26-28, 2023, Marne-la-Vallée, France, volume 259 of LIPIcs, pages 12:1–12:22. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2023. doi:10.4230/LIPICS.CPM.2023.12.
- [19] Pawel Gawrychowski, Garance Gourdel, Tatiana Starikovskaya, and Teresa Anna Steiner. Compressed consecutive pattern matching. In Ali Bilgin, James E. Fowler, Joan Serra-Sagristà, Yan Ye, and James A. Storer, editors, Data Compression Conference, DCC 2024, Snowbird, UT, USA, March 19-22, 2024, pages 163–172. IEEE, 2024. doi:10.1109/DCC58796.2024.00024.
- [20] Daniel Gibney, Paul Macnichol, and Sharma V. Thankachan. Non-overlapping indexing in BWT-runs bounded space. In Franco Maria Nardini, Nadia Pisanti, and Rossano Venturini, editors, String Processing and Information Retrieval - 30th International Symposium, SPIRE 2023, Pisa, Italy, September 26-28, 2023, Proceedings, volume 14240 of Lecture Notes in Computer Science, pages 260–270. Springer, 2023. doi:10.1007/978-3-031-43980-3_21.
- [21] Isaac Goldstein, Tsvi Kopelowitz, Moshe Lewenstein, and Ely Porat. Conditional lower bounds for space/time tradeoffs. In Faith Ellen, Antonina Kolokolova, and Jörg-Rüdiger Sack, editors, Algorithms and Data Structures - 15th International Symposium, WADS 2017, St. John’s, NL, Canada, July 31 - August 2, 2017, Proceedings, volume 10389 of Lecture Notes in Computer Science, pages 421–436. Springer, 2017. doi:10.1007/978-3-319-62127-2_36.
- [22] Sahar Hooshmand, Paniz Abedin, M. Oguzhan Külekci, and Sharma V. Thankachan. I/O-efficient data structures for non-overlapping indexing. Theor. Comput. Sci., 857:1–7, 2021. doi:10.1016/J.TCS.2020.12.006.
- [23] Orgad Keller, Tsvi Kopelowitz, and Moshe Lewenstein. Range non-overlapping indexing and successive list indexing. In Frank K. H. A. Dehne, Jörg-Rüdiger Sack, and Norbert Zeh, editors, Algorithms and Data Structures, 10th International Workshop, WADS 2007, Halifax, Canada, August 15-17, 2007, Proceedings, volume 4619 of Lecture Notes in Computer Science, pages 625–636. Springer, 2007. doi:10.1007/978-3-540-73951-7_54.
- [24] Tomasz Kociumaka. Minimal suffix and rotation of a substring in optimal time. In Roberto Grossi and Moshe Lewenstein, editors, 27th Annual Symposium on Combinatorial Pattern Matching, CPM 2016, June 27-29, 2016, Tel Aviv, Israel, volume 54 of LIPIcs, pages 28:1–28:12. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. doi:10.4230/LIPICS.CPM.2016.28.
- [25] Tomasz Kociumaka, Jakub Radoszewski, Wojciech Rytter, and Tomasz Walen. Internal pattern matching queries in a text and applications. SIAM J. Comput., 53(5):1524–1577, 2024. doi:10.1137/23M1567618.
- [26] Veli Mäkinen and Gonzalo Navarro. Rank and select revisited and extended. Theor. Comput. Sci., 387(3):332–347, 2007. doi:10.1016/J.TCS.2007.07.013.
- [27] Kazuki Mitani, Takuya Mieno, Kazuhisa Seto, and Takashi Horiyama. Finding top-k longest palindromes in substrings. Theor. Comput. Sci., 979:114183, 2023. doi:10.1016/J.TCS.2023.114183.
- [28] Gonzalo Navarro and Sharma V. Thankachan. Reporting consecutive substring occurrences under bounded gap constraints. Theor. Comput. Sci., 638:108–111, 2016. doi:10.1016/J.TCS.2016.02.005.
- [29] Yakov Nekrich and Gonzalo Navarro. Sorted range reporting. In Algorithm Theory–SWAT 2012: 13th Scandinavian Symposium and Workshops, Helsinki, Finland, July 4-6, 2012. Proceedings 13, pages 271–282. Springer, 2012. doi:10.1007/978-3-642-31155-0_24.
- [30] Mihai Pătraşcu and Mikkel Thorup. Dynamic integer sets with optimal rank, select, and predecessor search. In 55th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2014, Philadelphia, PA, USA, October 18-21, 2014, pages 166–175. IEEE Computer Society, 2014. doi:10.1109/FOCS.2014.26.
- [31] Saladi Rahul and Ravi Janardan. A general technique for top- geometric intersection query problems. IEEE Transactions on Knowledge and Data Engineering, 26(12):2859–2871, 2014. doi:10.1109/TKDE.2014.2316807.
- [32] Milan Ruzic. Constructing efficient dictionaries in close to sorting time. In Luca Aceto, Ivan Damgård, Leslie Ann Goldberg, Magnús M. Halldórsson, Anna Ingólfsdóttir, and Igor Walukiewicz, editors, Automata, Languages and Programming, 35th International Colloquium, ICALP 2008, Reykjavik, Iceland, July 7-11, 2008, Proceedings, Part I: Tack A: Algorithms, Automata, Complexity, and Games, volume 5125 of Lecture Notes in Computer Science, pages 84–95. Springer, 2008. doi:10.1007/978-3-540-70575-8_8.
- [33] Qingmin Shi and Joseph JaJa. Optimal and near-optimal algorithms for generalized intersection reporting on pointer machines. Information Processing Letters, 95(3):382–388, 2005. doi:10.1016/j.ipl.2005.04.008.
- [34] Qingmin Shi and Joseph JaJa. Fast fractional cascading and its applications. Digital Repository at the University of Maryland, 2008. URL: https://www.researchgate.net/publication/228922992.
- [35] Hiroki Shibata and Dominik Köppl. LZ78 substring compression with CDAWGs. In Zsuzsanna Lipták, Edleno Silva de Moura, Karina Figueroa, and Ricardo Baeza-Yates, editors, String Processing and Information Retrieval - 31st International Symposium, SPIRE 2024, Puerto Vallarta, Mexico, September 23-25, 2024, Proceedings, volume 14899 of Lecture Notes in Computer Science, pages 289–305. Springer, 2024. doi:10.1007/978-3-031-72200-4_22.
- [36] Daniel D. Sleator and Robert Endre Tarjan. A data structure for dynamic trees. Journal of Computer and System Sciences, 26(3):362–391, 1983. doi:10.1016/0022-0000(83)90006-5.
- [37] Peter Weiner. Linear pattern matching algorithms. In 14th Annual Symposium on Switching and Automata Theory, Iowa City, Iowa, USA, October 15-17, 1973, pages 1–11. IEEE Computer Society, 1973. doi:10.1109/SWAT.1973.13.
