Cheriton School of Computer Science, University of [email protected], Massachusetts Institute of [email protected] \CopyrightBryce Sandlund and Yinzhan Xu \ccsdesc[500]Theory of computation Data structures design and analysis \supplement
Acknowledgements.
We would like to thank Virginia Vassilevska Williams for her valuable comments on a draft of this paper. We would like to thank the anonymous reviewers for their helpful suggestions.\hideLIPIcs\EventEditorsJohn Q. Open and Joan R. Access \EventNoEds2 \EventLongTitle42nd Conference on Very Important Topics (CVIT 2016) \EventShortTitleCVIT 2016 \EventAcronymCVIT \EventYear2016 \EventDateDecember 24–27, 2016 \EventLocationLittle Whinging, United Kingdom \EventLogo \SeriesVolume42 \ArticleNo23Faster Dynamic Range Mode
Abstract
In the dynamic range mode problem, we are given a sequence of length bounded by and asked to support element insertion, deletion, and queries for the most frequent element of a contiguous subsequence of . In this work, we devise a deterministic data structure that handles each operation in worst-case time, thus breaking the per-operation time barrier for this problem. The data structure is achieved by combining the ideas in Williams and Xu (SODA 2020) for batch range mode with a novel data structure variant of the Min-Plus product.
keywords:
Range Mode, Min-Plus Productcategory:
\relatedversion1 Introduction
Given a sequence of elements , the dynamic range mode problem asks to support queries for the most frequent element in a specified subsequence while also supporting insertion or deletion of an element at a given index . The mode of a sequence of elements is one of the most basic data statistics, along with the median and the mean. It is frequently computed in data mining, information retrieval, and data analytics.
The range mode problem seeks to answer multiple queries on distinct intervals of the data sequence without having to recompute each answer from scratch. Its study in the data structure community has shown that the mode is a much more challenging data statistic to maintain than other natural range queries: while range sum, min or max, median, and majority all support linear space dynamic data structures with poly-logarithmic or better time per operation [22, 7, 16, 12, 10], the current fastest dynamic range mode data structure prior to this paper requires a stubborn time per operation [9]. Indeed, range mode is one of few remaining classical range queries to which our currently known algorithms may be far from optimal. As originally stated by Brodal et al. [4] and mentioned by Chan et al. [6] in 2011 and 2014, respectively, “The problem of finding the most frequent element within a given array range is still rather open.”
The current best conditional lower bound, by Chan et al. [6], reduces multiplication of two boolean matrices to range mode queries on a fixed array of size . This indicates that if the current algorithm for boolean matrix multiplication is optimal, then answering range mode queries on an array of size cannot be performed in time better than time for with combinatorial techniques, or time for in general, where [25, 13] is the square matrix multiplication exponent. This reduction can be strengthened for dynamic range mode by reducing from the online matrix-vector multiplication problem [17]. Using dynamic range mode operations on a sequence of length , we can multiply a boolean matrix with boolean vectors given one at a time. This indicates that a dynamic range mode data structure taking time per operation for is not possible with current knowledge.
Previous attempts indicate the higher per operation cost as the bound to beat [6, 9]. Indeed, time per operation111We use the notation to hide poly-logarithmic factors. can be achieved with a variety of techniques, but crossing the barrier appears much harder.
Progress towards this goal has been established with the recent work of Williams and Xu [26]. They show that by appealing to Min-Plus product of structured matrices, range mode queries on an array of size can be answered in time, thus beating the combinatorial lower bound for batch range mode. This result also shows a separation between batch range mode and dynamic range mode: while batch range mode can be completed in time per operation, such a result for dynamic range mode would imply a breakthrough in the online matrix-vector multiplication problem.
Range mode is not the first problem shown to be closely related to the Min-Plus product problem. It is well-known that the all-pairs shortest paths (APSP) problem is asymptotically equivalent to Min-Plus product [11], in the sense that a time algorithm to compute the Min-Plus product of two matrices implies an time algorithm for APSP in -node graphs and vice versa. Although it is not known how to perform Min-Plus product of two arbitrary matrices in time for , several problems reduce to Min-Plus products of matrices and which have nice structures that can be exploited. The simplest examples result by restricting edge weights in APSP problems [23, 24, 28, 5, 27]. Bringmann et al. [3] show Language Edit Distance, RNA-folding, and Optimum Stack Generation can be reduced to Min-Plus product where matrix has small difference between adjacent entries in each row and column. Finally, the recent work of Williams and Xu [26] reduces APSP in certain geometric graphs, batch range mode, and the maximum subarray problem with entries bounded by to a more general structured Min-Plus product, extending the result of Bringmann et al. All of the above structured Min-Plus products are solvable in truly subcubic time for , improving algorithms in the problems reduced to said product.
The connection and upper bound established by Williams and Xu [26] of batch range mode to Min-Plus product suggest other versions of the range mode problem may be amenable to similar improvements. In particular, the ability to efficiently compute a batch of range mode queries via reducing to a structured Min-Plus product suggests that one might be able to improve the update time of dynamic range mode in a similar way.
1.1 Our Results
In this paper, we break the time per operation barrier for dynamic range mode. We do so by adapting the result of Williams and Xu [26]. Specifically, we define the following new type of data structure problem on the Min-Plus product that can be applied to dynamic range mode, which may be of independent interest. Then we combine this data structure problem with the algorithm of Williams and Xu.
Problem \thetheorem (Min-Plus-Query problem).
During initialization, we are given two matrices . For each query, we are given three parameters , where are two integers, and is a set of integers. The query asks .
Our performance theorem is the following.
Theorem 1.1.
There exists a deterministic data structure for dynamic range mode on a sequence that supports query, insertion, and deletion in worst-case time per operation, where is the maximum size of the sequence at any point in time. The space complexity of the data structure is .
Our result shows yet another application of the Min-Plus product to an independently-studied problem, ultimately showing a dependence of the complexity of dynamic range mode on the complexity of fast matrix multiplication. Further, in contrast to many other reductions to Min-Plus in which we must assume a structured input on the original problem [23, 24, 28, 5, 27, 26], our algorithm works on the fully general dynamic range mode problem. In this sense, our result is perhaps most directly comparable to the batch range mode reduction of Williams and Xu [26] and the Language Edit Distance, RNA-folding, and Optimum Stack Generation reductions of Bringmann et al. [3].
1.2 Discussion of Technical Difficulty
Despite the new time algorithm for batch range mode [26], we cannot directly apply the result to dynamic range mode. The main issue is the element deletion operation. In the range mode algorithm of Williams and Xu (and in many other range mode algorithms), critical points are chosen evenly distributed in the array, and the algorithm precomputes the range mode of intervals between every pair of critical points. In [26], the improvement is achieved via a faster precomputation algorithm, which uses a Min-Plus product algorithm for structured matrices. However, if element deletion is allowed, the results stored in the precomputation will not be applicable. For example, an interval between two critical points could contain copies of element , copies of element , and many other elements with frequencies less than . During precomputation, the range mode of this interval would be . However, if we delete two copies of , there is no easy way to determine that the mode of this interval has now changed to .
We overcome this difficulty by introducing the Min-Plus-Query problem, as defined in Section 1.1. Intuitively, in the Min-Plus-Query problem, a large portion of the work of the Min-Plus product is put off until the query. It also supports more flexible queries. Using the Min-Plus-Query problem as a subroutine, we will be able to query the most frequent element excluding a set of forbidden elements. For instance, in the preceding example, we would be able to query the most frequent element that is not . This is the main technical contribution of the paper.
Another major difference between our algorithm for dynamic range mode and the batch range mode algorithm of Williams and Xu [26] is the need for rectangular matrix multiplication. In our algorithm, we treat elements that appear more than about times differently from the rest (a similar treatment is given in the dynamic range mode algorithm of Hicham et al. [9]). However, the number of critical points we use is about ; thus the number of critical points and frequent elements differ. This contrasts with batch range mode, where elements that appear more than about times are considered frequent and the number of critical points used coincides with the number of frequent elements. The consequence of this difference is that a rectangular matrix product is required for dynamic range mode, while a square matrix product sufficed in [26].
2 Related Work
The range mode problem was first studied formally by Krizanc et al. [18]. They study space-efficient data structures for static range mode, achieving a time-space tradeoff of space and query time for any . They also give a solution occupying space with time per query.
Chan et al. [6] also study static range mode, focusing on linear space solutions. They achieve a linear space data structure supporting queries in time via clever use of arrays, which can be improved to time via bit-packing tricks. Their paper also introduces the conditional lower bound which reduces multiplication of two boolean matrices to range mode queries on an array of size . As mentioned, combined with the presumed hardness of the online matrix vector problem [17], this result indicates a dynamic range mode data structure must take greater than for time per operation. Finally, Chan et al. [6] also give the first data structure for dynamic range mode. At linear space, their solution achieves worst-case time per query and amortized expected time update, and at space, their solution achieves worst-case time query and amortized expected update time.
Recently, Hicham et al. [9] improved the runtime of dynamic range mode to worst-case time per operation while simultaneously improving the space usage to linear. Prior to this paper, this result was the fastest data structure for dynamic range mode.
A cell-probe lower bound for static range mode has been devised by Greve et al. [15]. Their result states that any range mode data structure that uses memory cells of -bit words needs time to answer a query.
Via reduction to a structured Min-Plus product, Williams and Xu [26] recently showed that range mode queries on a fixed array of size can be answered in time. Williams and Xu actually show how to compute the frequency of the mode for each query. We can adapt this method to find the element that is mode using the following binary search. For query , we ask the frequency of the mode in range . If it is the same, we repeat the search with right endpoint in range ; if it is not, we repeat the search with right endpoint in range . Using this method, we can binary search until we determine when the frequency of the mode changes, thus finding the element that is mode in an additional queries. The algorithm of Williams and Xu can also be used to speed up the preprocessing time of the space, query time static range mode data structure to time.
3 Preliminaries
We formally define the Min-Plus product problem and the dynamic range mode problem.
Problem 3.1 (Min-Plus product).
The Min-Plus product of an matrix and an matrix is the matrix such that .
Problem 3.2 (Dynamic Range Mode).
In the dynamic range mode problem, we are given an initially empty sequence and must support the following operations:
-
•
Insert an element at a given position of the sequence.
-
•
Delete one element of the sequence.
-
•
Query the most frequent element of any contiguous subsequence. If there are multiple answers, output any.
It is guaranteed that the size of the array does not exceed at any point in time.
We use to denote the square matrix multiplication exponent, i.e. the smallest real number such that two matrices can be multiplied in time. The current bound on is [13, 25]. In this work, we will use fast rectangular matrix multiplication. Analogous to the square case, we use to denote the exponent of rectangular matrix multiplication, i.e., the smallest real number such that an matrix and an matrix can be multiplied in time. Le Gall and Urrutia [14] computed smallest upper bounds to date for various values of . In this work, we are mostly interested in values of listed in Figure 1.
Upper Bound on | |
---|---|
It is known that the function is convex for (see e.g. [19], [20]), so we can use values of and to give upper bounds for as long as .
Fact 1.
When , .
Corollary 3.3.
When , .
4 Main Algorithm
A main technical component for our dynamic range mode algorithm is the use of the Min-Plus-Query problem, which is formally defined in Section 1. We are given two matrices . For each query, we are given three parameters , and we need to compute .
If we just use the Min-Plus-Query problem, we can only compute the frequency of the range mode. Although we can binary search for the most frequent element as described in Section 2, we are also able to return the witness from the Min-Plus-Query problem organically. This construction may be of independent interest.
Problem 4.1 (Min-Plus-Query-Witness problem).
During initialization, we are given two matrices . For each query, we are given three parameters , where are two integers, and is a set of integers. We must output an index such that .
If is an matrix and is an matrix, then the naive algorithm for Min-Plus-Query just enumerates all possible indices for each query, which takes time per query. In order to get a faster algorithm for dynamic range mode, we need to achieve preprocessing time and query time, for some , where are some special matrices generated by the range mode instance. Specifically, matrix meets the following two properties:
-
1.
Each row of is non-increasing;
-
2.
The difference between the sum of elements in the -th column and the sum of elements in the -th column is at most , for any .
Williams and Xu [26] give a faster algorithm for multiplying an arbitrary matrix with such matrix , which leads to a faster algorithm for static range mode. We will show that nontrivial data structures exist for the Min-Plus-Query problem for such input matrices and . Such a data structure will lead to a faster algorithm for dynamic range mode.
In the following lemma, we show a data structure for the Min-Plus-Query problem when both input matrices have integer weights small in absolute value.
Lemma 4.2.
Let be a constant. Let and be two integer matrices of dimension and , respectively, with entries in for some . Then we can solve the Min-Plus-Query problem of and in preprocessing time and query time. The space complexity is .
Proof 4.3.
The algorithm uses the idea by Alon, Galil and Margalit in [1], which computes the Min-Plus product of in time.
In their algorithm, they first construct matrix defined by
We can define similarly. Then the product captures some useful information about the Min-Plus product of and . Namely, for each entry , we can uniquely write it as for integers . Note that exactly equals the number of such that . Thus, we can use to compute the Min-Plus Product of and .
In our algorithm, we use a range tree to maintain the sequence for each pair of . The preprocessing takes time, which is the time to compute and the sequences .
During each query, we are given . We enumerate each , and decrement in the range tree if . After we do this for every , we query the range tree for the smallest such that , so is the answer to the Min-Plus-Query query. After each query, we need to restore the values of , which can also be done efficiently. The query time is , since each update and each query of range tree takes time. The space complexity should be clear from the algorithm.
In the previous lemma, the data structure only answers the Min-Plus-Query problem. In all subsequent lemmas, the data structure will be able to handle the Min-Plus-Query-Witness problem.
In the next lemma, we use Lemma 4.2 as a subroutine to show a data structure for the Min-Plus-Query-Witness problem when only matrix has small integer weights in absolute value.
Lemma 4.4.
Let be a constant. Let and be two integer matrices of dimension and , respectively, where has entries in for some , and has arbitrary integer entries represented by bit numbers. Then for every integer , we can solve the Min-Plus-Query-Witness problem of and in preprocessing time and query time. The space complexity is .
Proof 4.5.
For simplicity, assume is a factor of . We sort each column of matrix and put entries whose rank is between and into the -th bucket. We use to denote the set of row indices of entries in the -th bucket of the column . We use to denote the smallest entry value of the bucket , and use to denote the largest entry value. Formally,
For each , we do the following222We use , with integer, to denote the set .. We create an matrix and initialize all its entries to . Then for each column , if (we will call it a small bucket), we set for all . We will handle the case (large bucket) later. Clearly, all entries in have values in , so we can use the algorithm in Lemma 4.2 to preprocess and and store the data structure in . Also, for each pair , we create a range tree on the sequence , , which stores the optimal Min-Plus values when is from a specific small bucket. This part takes time. The space complexity is times more than the space complexity of Lemma 4.2, so space complexity of this part is .
We also do the following preprocessing for buckets where . We first create a matrix where if and only if . Then for each , we create a matrix such that if and only if and . Then we use fast matrix multiplication to compute the product . If is a large bucket, the -th entry of is the number of such that ; if is a small bucket, the -th entry is . For each pair , we create a range tree on the sequence . This part takes time, which is dominated by the time for small buckets. The space complexity is also dominated by the data structures for small buckets.
Now we describe how to handle a query . First consider small buckets. In time, we can compute the set of small buckets that intersect with . For each such , we can query the data structure with input to get the optimum value when . For each small bucket that intersects with , we can set its corresponding value in the range tree to , then we can compute the optimum value of all small buckets that do not intersect with by querying the minimum value of the range tree . After this query, we need to restore all values in the range tree. It takes time to handle small buckets on query.
Now consider large buckets. Intuitively, we want to enumerate indices in all large buckets such that there exists an index where . However, doing so would be prohibitively expensive. We will show that we only need two such buckets. Consider three large buckets . Pick any such that . Since
can never be the optimum. Thus, it suffices to find the smallest two buckets such that there exists an index where , and then enumerate all indices in these two buckets. To find such two buckets, we can enumerate over all indices , and if we can decrement the corresponding value in the range tree . Thus, we can compute the two smallest buckets by querying the two earliest nonzero values in the range tree. We also need to restore the range tree after the query. The range tree part takes time and scanning the two large buckets requires time. Thus, this step takes time.
At this point, we will know the bucket that contains the optimum index . Thus, we can iterate all indices in this bucket to actually get the witness for the Min-Plus-Query-Witness query. It takes time to do so.
In summary, the preprocessing time, query time, and space complexity meet the promise in the lemma statement.
In the following lemma, we show a data structure for the Min-Plus-Query-Witness problem when the matrix has the bounded difference property, which means that nearby entries in each row have close values. The proof adapts the strategy of [26].
Lemma 4.6.
Let be a constant. Let be an integer matrix, and let be an integer matrix. It is guaranteed that there exists , such that for every , as long as . Then for every , we can solve the Min-Plus-Query-Witness problem of and in preprocessing time and query time, when . The space complexity is .
Proof 4.7.
Preprocessing Step 1: Create an Estimation Matrix
First, we create a matrix , where . By the property of matrix , for every . For each pair , we compute the -th smallest value of among all , and denote this value by . Notice that , so it suffices to compute when is a multiple of , and we can infer other values correctly. It takes time to compute each , so this step takes time.
If we similarly define as the -th smallest value of among all , then by the following claim, whose proof is omitted for space constraint.
Given two sequences and such that , then the -th smallest element of and the the -th smallest element of differ by at most .
Also, in time, we can compute a sorted list of indices sorted by the value , for every , and every that is a multiple of .
The space complexity in this step is not dominating.
Preprocessing Step 2: Perform Calls to Lemma 4.4
For some integer , we will perform rounds of the following algorithm. At the -th round for some , we randomly sample , and let and . Clearly, . For each pair , we find the smallest such that . We keep these entries as they are and replace all other entries by . For every , there exists at most one such that . Then we use Lemma 4.4 to preprocess and for every . Thus, this part takes time, for some integer to be determined later. Note that this parameter also affects the query time. This step stores copies of the data structure from Lemma 4.4, so the space complexity is .
Note that this step is the only step that uses randomization. We can use the method of [26], Appendix A, to derandomize it. We omit the details for simplicity.
Preprocessing Step 3: Handling Uncovered Pairs
For a pair , if for any , we call covered; otherwise, we call the pair uncovered. For each pair , we enumerate all such that and is uncovered. Notice that since , we only need to exhaustively enumerate all when is a multiple of . Thus, if the total number of where and is uncovered is , then we can enumerate all such triples in time.
It remains to bound the total number of triples that satisfy the condition. Fix an arbitrary pair , and suppose the number of such that is at least . Then with probability at least , we pick a where . Therefore,
which means is covered. Therefore, with high probability, all pairs of where the number of such that is at least will be covered. In other words, .
For each pair , if we enumerate more than indices , we only keep the values of that give the smallest values of . We call this list . From previous discussion, the time cost in this step is . Since we need to store all the triples, the space complexity is .
Handling Queries
Now we discuss how to handle queries. For each query , let be the optimum index. Consider two cases:
-
•
is covered. By definition of being covered, there exists a round such that , so . Therefore, we can query the data structure in Lemma 4.4 for every and and denote as the result. The answer is given by the smallest value of over all . The witness is given by the data structure of Lemma 4.4.
Note that when querying and , we only need to pass the set . For every , there is at most one such that , so the total size of the sets passing to the data structure of Lemma 4.4 is . Thus, this case takes time.
-
•
is uncovered. There are still two possibilities to consider in this case.
-
–
Possibility I: . In this case,
so the optimum value is smaller than . By reading the list , we can effectively find all such where in time linear to the number of such . The number of such is at most , by the definition of . Thus, this part takes time.
-
–
Possibility II: . In fact, in this case, we further have
where because . Therefore, in this case, we have , so we can enumerate all indices in and take the best choice. This takes time.
-
–
Time and Space Complexity
In summary, the preprocessing time is
and the query time is . To balance the terms, we can set and to achieve a preprocess time and a query time. Note that since we need , we must have .
From the preprocessing steps, the space complexity is . Plugging in and reduces this to
as given in the statement of the lemma.
The next lemma is our last data structure for Min-Plus-Query-Witness problems.
Lemma 4.8.
Let be a constant. Let be an integer matrix and be an integer matrix. Suppose matrix satisfies
-
1.
Each row of is non-increasing;
-
2.
The difference between the sum of elements in the -th column and the sum of elements in the -th column is at most , for any .
Then for every positive integer , we can solve the Min-Plus-Query-Witness problem of and in preprocessing time and query time, when . The space complexity is
Proof 4.9.
Let be small polynomials in to be fixed later. Define to be the interval .
Let be any multiple of . By property 2 of matrix , for any . Thus, we have
By averaging, there are at most indices such that . We create a new matrix , initially the same as matrix . For each such that , and for each , we set as , where is some large enough integer. After this replacement, for any and any multiple of . Also, since for any , we have that as long as . Therefore, we can use Lemma 4.6 to preprocess and in time. The space complexity is .
On the other hand, note that differs with on at most entries, so we need to do some extra preprocessing to handle those entries. For each pair , we initialize a range tree whose elements are all (it takes time to initialize each range tree if we implement it carefully). Then for every such that , we set the -th element in as . The total number of operations we perform in all the range trees are , so this part takes time. The space complexity is also .
During a query , we first query the data structure in Lemma 4.6 on matrix and with parameters . Then we query the minimum value from the range tree after setting all as for . Taking the minimum of these two queries gives the answer. The optimum index is either given by the data structure of Lemma 4.6 or can be obtained from the range tree.
Thus, the preprocessing time of the algorithm is
and the query time is . We get the desired preprocessing time by setting and . Since we need , we require that . In Lemma 4.6, we also requires that , but this is always true when .
By previous discussion, the space complexity is . Plugging in the value for and simplifies the complexity to
Proof 4.10 (Proof of Theorem 1.1).
For clarity, we will use element to refer to a specific item of the sequence and use value to refer to all elements of a given type. Given a pointer to an element of the sequence , we assume the ability to look up its index in the sequence in time by storing all elements of the sequence in a balanced binary search tree with worst-case time guarantees (e.g. a red-black tree). Thus we can go from index to element and back via appropriate rank and select queries on the balanced binary search tree. We may also add or remove an element from the sequence, and thus the binary search tree, in time.
Let be three parameters of the algorithm. Parameter is a threshold that controls the number of “frequent” colors, controls how frequently the data structure is rebuilt, and represents the size of blocks in the algorithm.
We call values that appear more than times frequent and all other values infrequent. Thus, there are at most frequent values at any point in time. Note that a fixed value can change from frequent to infrequent, or from infrequent to frequent, via a deletion or insertion.
Infrequent Values
First, we discuss how to handle infrequent values. We maintain balanced search trees . For balanced search tree , we prepare the key/value pairs in the following way. Fix a given value of the sequence. Say all its occurrences are at indices . Then we insert the key/value pairs to for every . However, the indices themselves would need updating when sequence is updated. Instead of inserting the indices themselves, we insert corresponding pointers to the nodes of the binary search tree that holds sequence . That way we can perform all comparisons using binary search tree operations in time, without needing to update indices when sequence changes. We also augment each balanced search tree so that every subtree stores the smallest value of any pair in the subtree. After an insertion or deletion, we need to update a total of pairs. Thus, we can maintain these balanced search trees in time per operation.
During a query , we iterate through all the balanced search trees . If there exists a pair such that , then the range mode is at least . Thus, if the range mode is an infrequent value, we can find its frequency and corresponding value by querying the balanced search trees. The query time is , which is not the dominating term.
Newly Modified Values
We now consider how to handle frequent values. We handle newly modified values and unmodified values differently. We will rebuild our data structure after every operations, and call values that are inserted or deleted after the last rebuild newly modified values.
For every value, we maintain a balanced search tree of occurrences of this value in the sequence. It takes time per operation to maintain such balanced search trees. Thus, given an interval , it takes time to query the number of occurrences of a particular value in the interval. We use this method to query the number of occurrences of each newly modified value. Since there can be at most such values, this part takes time per operation.
Data Structure Rebuild
It remains to handle the frequent, not newly modified values during each rebuild. In this case, we will assume we can split the whole array roughly equally into a left half and right half. We can recursively build the data structure on these two halves so that we may assume a range mode query interval has left endpoint in the left half and right endpoint in the right half. The recursive construction adds only a poly-logarithmic factor to the complexity.
We split the left half and the right half into consecutive segments of length at most , so that there are segments. We call the segments in the left half and in the right half, where segments with a smaller index are closer to the middle of the sequence.
Let be the frequent values during the rebuild. We create a matrix such that equals the negation of the number of occurrences of in segments ; similarly, we create a matrix such that equals the negation of the number of occurrences of in segments . Note that the negation of the value is the frequency of value in the interval from to . It is not hard to verify that matrix satisfies the requirement of Lemma 4.8. We take the negation here since Lemma 4.8 handles -product instead of -product. Then we use the preprocessing part of Lemma 4.8 with matrices , and . If we let , then in the notation of Lemma 4.8, and , so and . Thus, by Lemma 4.8 the rebuild takes
time. Since we perform the rebuild every operations, the amortized cost of rebuild is
per operation.
Now we discuss how to handle queries for frequent, unmodified elements. For a query interval , we find all the segments inside the interval . The set of such segments must have the form for some . We scan through all elements in , and use their frequency to update the answer. Since the size of segments is , the time complexity to do so is .
For the segments , we query the data structure in Lemma 4.8 with being the set of newly modified elements. The answer will be the most frequent element in the interval from to that is not newly modified. By Lemma 4.8 this takes time per operation.
Time and Space Complexity
In summary, the amortized cost per operation is
To balance the terms, we set , and . The time complexity thus becomes
By observation, we can note that the optimum value of lies in . Thus, we can plug in Corollary 3.3 and use to balance the two terms. This gives an amortized time per operation algorithm.
The space usage has two potential bottlenecks. The first is the space to store for handling infrequent elements, which is . The second is the space used by Lemma 4.8, which is
By plugging in the values for and , the space complexity becomes , with the term being the dominating term.
Worst-Case Time Complexity
By applying the global rebuilding of Overmars [21], we can achieve a worst-case time bound. The basic idea is that after operations, we don’t immediately rebuild the Min-Plus-Query-Witness data structure. Instead, we rebuild the data structure during the next operations, spreading the work evenly over each operation. To answer queries during these operations, we use the previous build of the Min-Plus-Query-Witness data structure. By this technique, the per-operation runtime can be made worst-case.
References
- [1] Noga Alon, Zvi Galil, and Oded Margalit. On the exponent of the all pairs shortest path problem. J. Comput. Syst. Sci., 54(2):255–262, 1997.
- [2] Prosenjit Bose, Evangelos Kranakis, Pat Morin, and Yihui Tang. Approximate range mode and range median queries. In Annual Symposium on Theoretical Aspects of Computer Science, 2005.
- [3] Karl Bringmann, Fabrizio Grandoni, Barna Saha, and Virginia Williams. Truly sub-cubic algorithms for language edit distance and rna folding via fast bounded-difference min-plus product. SIAM Journal on Computing, 48, 07 2017. doi:10.1137/17M112720X.
- [4] Gerth Stølting Brodal, Beat Gfeller, Allan Jørgensen, and Peter Sanders. Towards optimal range medians. In Theoretical Computer Science, 2011.
- [5] Timothy M. Chan. More algorithms for all-pairs shortest paths in weighted graphs. SIAM J. Comput., 39(5):2075–2089, 2010.
- [6] Timothy M. Chan, Stephane Durocher, Kasper Green Larsen, Jason Morrison, and Bryan T. Wilkinson. Linear-space data structures for range mode query in arrays. Theory of Computing Systems, 55:719–741, 2014.
- [7] Timothy M Chan and Konstantinos Tsakalidis. Dynamic orthogonal range searching on the ram, revisited. In LIPIcs-Leibniz International Proceedings in Informatics, volume 77. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2017.
- [8] Hicham El-Zein, Meng He, J. Ian Munro, Yakov Nekrich, and Bryce Sandlund. On approximate range mode and range selection. In 30th International Symposium on Algorithms and Computation (ISAAC 2019), 2019.
- [9] Hicham El-Zein, Meng He, J. Ian Munro, and Bryce Sandlund. Improved time and space bounds for dynamic range mode. In Proceedings of the 26th Annual European Symposium on Algorithms, pages 25:1–25:13, 2018.
- [10] Amr Elmasry, Meng He, J Ian Munro, and Patrick K Nicholson. Dynamic range majority data structures. In International Symposium on Algorithms and Computation, pages 150–159. Springer, 2011.
- [11] Michael J Fischer and Albert R Meyer. Boolean matrix multiplication and transitive closure. In n 12th Annual Symposium on Switching and Automata Theory, pages 129–131. IEEE, 1971.
- [12] Travis Gagie, Meng He, and Gonzalo Navarro. Compressed dynamic range majority data structures. In Data Compression Conference (DCC), 2017, pages 260–269. IEEE, 2017.
- [13] François Le Gall. Powers of tensors and fast matrix multiplication. In International Symposium on Symbolic and Algebraic Computation, ISSAC 2014, Kobe, Japan, July 23-25, 2014, pages 296–303, 2014.
- [14] François Le Gall and Florent Urrutia. Improved rectangular matrix multiplication using powers of the coppersmith-winograd tensor. In Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 1029–1046. SIAM, 2018.
- [15] Mark Greve, Allan Grønlund Jørgensen, Kasper Dalgaard Larsen, and Jakob Truelsen. Cell probe lower bounds and approximations for range mode. In International Colloquium on Automata, Languages, and Programming, 2010.
- [16] Meng He, J. Ian Munro, and Patrick K. Nicholson. Dynamic range selection in linear space. In International Symposium on Algorithms and Computation, 2011.
- [17] Monika Henzinger, Sebastian Krinninger, Danupon Nanongkai, and Thatchaphol Saranurak. Unifying and strengthening hardness for dynamic problems via the online matrix-vector multiplication conjecture. In Proceedings of the Forty-Seventh Annual ACM Symposium on Theory of Computing, page 21–30, 2015.
- [18] Danny Krizanc, Pat Morin, and Michiel Smid. Range mode and range median queries on lists and trees. Nordic Journal of Computing, 2005.
- [19] François Le Gall. Faster algorithms for rectangular matrix multiplication. In 2012 IEEE 53rd annual symposium on foundations of computer science, pages 514–523. IEEE, 2012.
- [20] Grazia Lotti and Francesco Romani. On the asymptotic complexity of rectangular matrix multiplication. Theoretical Computer Science, 23(2):171–185, 1983.
- [21] Mark H Overmars. The design of dynamic data structures, volume 156. Springer Science & Business Media, 1983.
- [22] Mihai Pătraşcu and Emanuele Viola. Cell-probe lower bounds for succinct partial sums. In Proceedings of the twenty-first annual ACM-SIAM symposium on Discrete Algorithms, pages 117–122. Society for Industrial and Applied Mathematics, 2010.
- [23] Raimund Seidel. On the all-pairs-shortest-path problem in unweighted undirected graphs. J. Comput. Syst. Sci., 51(3):400–403, 1995.
- [24] Avi Shoshan and Uri Zwick. All pairs shortest paths in undirected graphs with integer weights. In 40th Annual IEEE Symposium on Foundations of Computer Science, pages 605–615, 1999.
- [25] Virginia Vassilevska Williams. Multiplying matrices faster than Coppersmith-Winograd. In Proceedings of the 44th Symposium on Theory of Computing Conference, STOC 2012, New York, NY, USA, May 19 - 22, 2012, pages 887–898, 2012.
- [26] Virginia Vassilevska Williams and Yinzhan Xu. Truly subcubic min-plus product for less structured matrices, with applications. In Proceedings of the 2020 ACM-SIAM Symposium on Discrete Algorithms, 2020.
- [27] Raphael Yuster. Efficient algorithms on sets of permutations, dominance, and real-weighted apsp. In 20th Annual ACM-SIAM Symposium on Discrete Algorithms, pages 950–957, 2009.
- [28] Uri Zwick. All pairs shortest paths using bridging sets and rectangular matrix multiplication. J. ACM, 49(3):289–317, 2002.