Dynamic Longest Increasing Subsequence and the Erdös-Szekeres Partitioning Problem
aa r X i v : . [ c s . D S ] J a n Dynamic Longest Increasing Subsequence and the Erd¨os-SzekeresPartitioning Problem ∗ Michael Mitzenmacher † Saeed Seddighin ∗ Abstract
In this paper, we provide new approximation algorithms for dynamic variations of the longestincreasing subsequence (
LIS ) problem, and the complementary distance to monotonicity (
DTM )problem. In this setting, operations of the following form arrive sequentially: (i) add an el-ement, (ii) remove an element, or (iii) substitute an element for another. At every point intime, the algorithm has an approximation to the longest increasing subsequence (or distance tomonotonicity). We present a (1 + ǫ )-approximation algorithm for DTM with polylogarithmicworst-case update time and a constant factor approximation algorithm for
LIS with worst-caseupdate time ˜ O ( n ǫ ) for any constant ǫ > LIS leads to an almost optimal algorithm for the Erd¨os-Szekerespartitioning problem. Erd¨os-Szekeres partitioning problem was introduced by Erd¨os and Szek-eres in 1935 and was known to be solvable in time O ( n . log n ). Subsequent work improve theruntime to O ( n . ) only in 1998. Our dynamic LIS algorithm leads to a solution for Erd¨os-Szekeres partitioning problem with runtime ˜ O ǫ ( n ǫ ) for any constant ǫ > Longest increasing subsequence (
LIS ) is one of the oldest problems in computer science. Given anarray a = h a , a , . . . , a n i of size n , LIS is defined as the largest subset of the elements whose valuesare strictly increasing in the order of their indices. Distance to monotonicity (
DTM ) is the dualproblem. For
DTM , we wish to remove the smallest number of elements such that the remainingsubsequence is increasing.
LIS and
DTM are special cases of the celebrated edit distance and longestcommon subsequence problems when the input strings are permutations.The classic patience sorting solution for
LIS utilizes dynamic programming and binary searchto solve
LIS exactly in time O ( n log n ). (In what follows, when we refer to a solution, we typicallyrefer to the size of the LIS , but also the corresponding increasing subsequence can be found intime proportional to its size.) Matching lower bounds (Ω( n log n )) are known for comparison-basedalgorithms [13] and solutions based on algebraic decision trees [31]. For approximation algorithms,for any ǫ >
0, a multiplicative O ( n ǫ ) approximate solution can be determined in truly sublineartime via random sampling . Surprisingly, not much is known that improves upon this algorithmgenerally, although when n/ LIS ( a ) is subpolynomial we can obtain better approximation guaranteesfor LIS [32, 33]. ∗ The results of this manuscript appeared in preliminary versions [24] (STOC’20) and [25]. † Toyota Technological Institute at Chicago For an O ( n ǫ ) approximation algorithm, one can sample O ( n − ǫ ) many elements from the array and report the LIS of those samples. rom a complexity point of view, unconditional lower bounds apply to
LIS . For instance, anyalgorithm that obtains an f ( n ) approximate solution for LIS has to make at least n/ ( f ( n ) + 1)value queries to the elements of a to distinguish the case that a is decreasing from the case that a has an increasing subsequence of length at least f ( n ) + 1. Thus a subpolynomial approximationalgorithm for LIS in truly sublinear time is not possible in general. Even if we are guaranteed thatthe solution size is Θ( n − ǫ ) (a setting for which the known complexity lower bounds do not apply),we are not aware of any subpolynomial approximate solution for LIS . Very recently, Rubinstein etal. [32] obtain O ( n ǫ ) approximation in time ˜ O ( n . ǫ ) in this case. Also, these lower bounds donot hold for stronger computational models such as quantum computation, but we do not havebetter general quantum approximation algorithms.In this work, we focus on approximation algorithms in the dynamic setting, where at eachstep, the array can be updated by inserting, deleting, or modifying an element. The goal is tomaintain an approximation of the correct value at each step. Dynamic settings for many problemshave been studied, e.g. [19, 27, 16, 4, 3, 7, 23, 5, 28]. In general, in dynamic settings the goal is todevelop an algorithm where the solution can be updated efficiently given incremental changes to theinput. In the context of graph algorithms [27, 28, 23, 4, 3, 5], such changes are usually modeled byedge addition or edge deletion. For string problems, changes are typically modeled with characterinsertion and character deletion [16, 7], as we consider here.We provide novel approximation algorithms for LIS and
DTM in the dynamic setting. For
LIS , for any 0 < ǫ <
1, we give a dynamic algorithm with worst-case update time ˜ O ( n ǫ ) andapproximation factor O ǫ (1); that is, for constant ǫ , the approximation factor is a constant thatdepends on ǫ . For DTM , we present an algorithm with approximation factor 1 + ǫ for any constant ǫ and worst-case update time O (log n ), where the order notation hides factors that can dependon ǫ . We primarily treat ǫ as constant since the exponent of the log factors suppressed by the˜ O notation may depend on 1 /ǫ . Here, n denotes the size of the array at the time the operationarrives. Thus the update time does not depend on the number of operations arrived prior to thenew operation. Problem Approximation factor Update time LIS ǫ ˜ O ( √ n ) LIS O ((1 /ǫ ) O (1 /ǫ ) ) ˜ O ( n ǫ ) LIS + O (log n ) O (log n ) DTM ǫ O (log n )Table 1: The results of this paper are summarized in this table. LIS + is a special case of LIS whereonly element insertion is allowed.
Our dynamic algorithm has an interesting application to a long-standing mathematical problem,namely the Erd¨os-Szekeres partitioning problem . It is well-known that any sequence of size n canbe decomposed into O ( √ n ) monotone subsequences. The proof follows from a simple fact: Anysequence of length n contains either an increasing subsequence of length √ n or a non-increasingsubsequence of length √ n . Thus, one can iteratively find the maximum increasing and the maximum A value query provides an i as input and asks for the value of a i . O ( √ n ) partitions. Thecomputational challenge, also known as the Erd¨os-Szekeres partitioning problem, is to do this inan efficient way. The above algorithm can be implemented in time O ( n . log n ) if we use patiencesorting in every iteration. Bar-Yehuda and Fogel [34] improve the runtime down to O ( n . ) bydesigning an algorithm that after a preprocessing step, solves LIS in time O ( n + k ) where thesolution size is bounded by k . Since any comparison-based algorithm takes time at least ˜Ω( n ), thegap for Erd¨os-Szekeres partitioning problem has been ˜Ω( √ n ) for quite a long time and the questionwas raised in a number of works as an important open problem [30, 18].We prove that via our dynamic LIS algorithm, the Erd¨os-Szekeres partitioning problem can besolved in time ˜ O ǫ ( n ǫ ) for any constant ǫ >
0. We assume that our algorithm performs as statedin Table 1.
Theorem 1.
For any constant ǫ > , one can in time ˜ O ǫ ( n ǫ ) partition any sequence of length n of distinct integer numbers into O ǫ ( √ n ) monotone (increasing or decreasing) subsequences.Proof. The proof follows directly from our algorithm for dynamic
LIS . In our dynamic setting, westart with an empty array a and at every point in time we are allowed to (i) add an element, or (ii)remove an element, or (iii) substitute an element for another. The algorithm is able to update thesequence and estimate the size of the LIS in time ˜ O ǫ ( | a | ǫ ) where | a | is the size of the array at thetime the operation is performed. Moreover, the approximation factor of our algorithm is constantas long as ǫ is constant. More precisely, our algorithm estimates the size of the longest increasingsubsequence within a multiplicative factor of at most (1 /ǫ ) O (1 /ǫ ) . It follows from our algorithmthat by spending additional time proportional to the reported estimation, our algorithm is able toalso find an increasing subsequence with size equal to the reported length.Given a sequence of length n with distinct numbers, we use the dynamic algorithm for LIS to decompose it into O ǫ ( √ n ) monotone subsequences in time ˜ O ǫ ( n ǫ ). To do so, we initializetwo instances of our dynamic algorithm that keep an approximation to the longest increasingsubsequence and the longest decreasing subsequence of the array. More precisely, in the firstinstance, we insert all elements of the array exactly the same way they appear in our sequence andin the second instance we insert the elements in the reverse order. Thus the dynamic algorithm forthe second instance always maintains an approximation to the longest decreasing subsequence ofour array.In every iteration, we estimate the size of the longest increasing and longest decreasing subse-quences of the array via the dynamic LIS algorithm. We then choose the maximum one and askthe algorithm to give us the sequence corresponding to the solution reported. Finally, we removethe elements from both instances of the dynamic algorithm and repeat the same procedure for theremainder of the elements.The total runtime of our algorithm is ˜ O ǫ ( n ǫ ) since we insert n elements in each of the instancesand then remove n elements which amounts to 2 n operations for each instance that runs in time˜ O ǫ ( n ǫ ). Moreover, because at every point in time the maximum estimate we receive from each ofthe dynamic algorithms is at least a constant fraction of the actual longest increasing subsequence,we repeat this procedure at most O ǫ ( √ n ) times. Therefore, we decompose the sequence into O ǫ ( √ n )monotone subsequences. 2 emark 1. The constant factor hidden in the O notation for the number of partitions is optimalin neither the algorithm of Theorem 1 nor the previous algorithm of [34] nor the simple greedyalgorithm that runs patience sorting in every step. Since our dynamic algorithm has constant approximation factor, in order to make sure the numberof partitions remains O ( √ n ), one needs to set ǫ to constant and therefore the gap between ourruntime of ˜ O ( n ǫ ) and the lower bound of Ω( n ) remains polynomial. Two independent subsequentwork further tighten the gap. Kociumaka and Seddighin [22] improve the gap to subpolynomialby presenting a dynamic algorithm with approximation factor 1 − o (1) and update time O ( n o (1) ).Gawrychowski and Janczewski [15] further tighten the gap to polylogarithmic by obtaining a similaralgorithm with polylogarithmic update time (with polynomial dependence on 1 /ǫ ). The work ofKociumaka and Seddighin [22] also gives the first exact algorithm for dynamic LIS with sublinearupdate time. Their algorithm is able to update the solution in time ˜ O ( n / ) after each operationand gives a correct solution with probability 1 − n − .In another subsequent work, Mitzenmacher and Seddighin [26] use the grid-packing techniquegiven here to obtain an improved sublinear time algorithm for approximating LIS . Their algorithmis able to obtain an approximation of
LIS in truly sublinear time within a factor of Ω( λ ǫ ) where ǫ > λ is the ratio of the solution size and the inputsize. LIS has received significant attention in the areas of property testing [11, 10, 12, 1], stream-ing [17, 14], and massively parallel computation (MPC) [20], as well as in the standard algorithmicsetting [13, 31, 32, 33]. Several questions remain open about approximation algorithms for
LIS .Although a linear lower bound on the runtime is trivial when the solution size is O (1), neitherconvincing lower bounds nor upper bounds are known for approximating LIS within subpolynomialmultiplicative factors if the solution size is larger ( ω (1)) in general. For a special case when n/ LIS ( a )is subpolynomial, we can approximate the solution size within a subpolynomial factor in sublineartime [32, 33]. In particular, Saks and Seshadhri [33] present a (1 + ǫ ) approximation algorithmfor LIS in sublinear time if the ratio of n over the solution size is sublogarithmic. The only priornon-trivial dynamic algorithm for LIS that we are aware of is the work of Chen et al. [7], wherethe authors present an exact dynamic algorithm for
LIS with worst-case update time O ( r + log n )when the solution size is bounded by r . The update time for this algorithm can grow up to Ω( n )if the solution size is Ω( n ).When the available memory is sublinear (as it is in the streaming and the MPC models),patience sorting can be used to compute a solution for smaller fragments of the input. Previouswork show that these local solutions can be cleverly merged to obtain 1 + ǫ approximate solutionsin the streaming [17] and the MPC models [20]. In contrast, our technique for approximating LIS is not based on patience sorting. We show it also has an application to a streaming variant of
LIS ,and we expect it will have additional applications in the future.Distance to monotonicity ( a.k.a
Ulam distance) is also a very well-studied problem [29, 2, 6, 33].While
LIS has resisted a multiplicative approximation algorithm,
DTM can be approximated within3 multiplicative factor 1 + ǫ in time ˜ O ( n/d + √ n ) when the solution size is lower bounded by d [29].Streaming [17] and MPC [6] algorithms for DTM have also appeared.
We consider the two problems,
LIS and
DTM . Input to both problems is an array a with arbitrarylength. For LIS , the goal is to find the length of the largest subsequence of elements such that theirvalues increase according to their indices. For
DTM the goal is to determine the smallest numberof elements such that the remaining subsequence is increasing. Obviously,
DTM ( a ) = | a | − LIS ( a ).However, an approximate solution for one problem does not imply an approximate solution for theother (much like maximum matching and vertex cover). We assume for simplicity and without lossof generality that all the numbers are distinct, although one can easily modify our algorithm tohandle repeated numbers.Our results here are for the dynamic setting. Initially, the input array is empty ( | a | = 0). Ateach step, an element is either inserted at an arbitrary position of the array or removed from anarbitrary position of the array. (Element substitution can also be implemented with the previoustwo operations, so we consider only insertions and removals.) We also study a special case of LIS where all operations add elements to the array. We call this problem
LIS + .We more formally define the array operations. Each insertion operation is of the form “ insert ( i, x )” where i is an integer between 1 and the length of the current array plus one. i specifies theposition of element x . After this operation, all the elements whose previous index was at least i will be shifted to the right. Similarly, an operation “ delete ( i )” removes the i ’th element of thearray and element i + 1 will replace its position. Likewise, all the elements whose previous indexwas at least i will be shifted to the left.For simplicity, in our algorithms we assume that at any point random access to the elements isprovided. That is, in every step, one can access the value of the i ’th element of the array as a valuequery. This brings an O (log n ) overhead to the runtime since one needs to design a data structurethat allows us element addition, element removal, and access to the i ’th element. Any balancedbinary tree ( e.g. red-black tree) suffices for that purpose [9]. We can also recover the position ofeach element of the array in logarithmic time with a balanced binary tree. Our main result is a dynamic algorithm for
LIS with worst-case update time ˜ O ( n ǫ ) and approxima-tion factor O ((1 /ǫ ) O (1 /ǫ ) ). Our algorithm is based on a novel technique which we call grid packing.In this section, we give a high-level summary of grid packing and our overall approach; Full proofsare given in Sections 4 and 5. In our work, to simplify our proofs, we utilize the notion of what we call a block-based algorithm .Very roughly speaking, a block-based algorithm starts with an array a of length n . It can use f ( n ) preprocessing time, after which it is responsible for a block of g ( n ) operations, where eachoperation has worst-case update time h ( n ). We show in Section 3 via a simple reduction that sucha block-based algorithm can be used to obtain a dynamic algorithm with worst-case update timemax { f ( n ) /g ( n ) , h ( n ) } . 4 motivating example shows the notion of block-based algorithms simplifies the analysis. Chen et al. [7] show that when LIS for an array is upper bounded by r , a dynamic algorithm can maintainthe exact solution for LIS with worst-case update time ˜ O ( r ). We show that this exact algorithmyields a dynamic (1 + ǫ )-approximation algorithm with worst-case update time ˜ O ( √ n ).We first provide the intuition and explain the complications. At any point in time, if the solutionvalue is below 2 √ n/ǫ , then the runtime guarantee is met by using the algorithm of Chen et al. [7].Otherwise, we can compute an exact solution, and then use the same value for up to √ n steps tomaintain a valid approximation. We then spend time ˜ O ( n ) for √ n operations, leading to amortizedupdate time of ˜ O ( √ n ). Deamortizing this approach to bound the worst-case update time seemscumbersome. The issue is that it is not clear when we should switch between the two algorithms.For example, if we define a threshold τ and switch between the algorithms when the solution sizecrosses the threshold τ , we may go back and forth across the threshold. We could consider multiplethresholds, but at this point we appear to be complicating the analysis beyond what should benecessary.Working with the framework of a block-based algorithm conveniently remedies the problem.Assuming we start with an array a of length n , we allow a preprocessing time of f ( n ) = O ( n log n )for the algorithm to compute the LIS . We set g ( n ) = √ n . If the LIS value r is above 2 √ n/ǫ , for thenext √ n steps, we report r − i in the i ’th step and can be sure that our solution is within a smallrange from the optimal one. Otherwise, we use the algorithm of Chen et al. [7] with worst-caseupdate time O ( √ n ) for the next √ n steps. Using the reduction, this turns to an algorithm withworst-case update time ˜ O ( √ n ) for LIS with approximation factor 1 + ǫ . Corollary
4, [restated informally].
For any constant ǫ > , there exists a dynamic algorithm for LIS with worst-case update time ˜ O ( √ n ) and approximation factor ǫ . As mentioned earlier, our algorithm for
LIS is based on a technique that we call grid packing. Gridpacking is defined on a table of m × m cells; the only parameter of the problem is m . The problemcan be thought of as a game between us and an adversary. We introduce a number of segmentson the table. Each segment covers a consecutive set of cells in either a row or in a column. Asegment A precedes a segment B if every cell of A is strictly higher than every cell of B and also every cell of A is strictly to the right of every cell of B . Two segments are non-conflicting , if oneof them precedes the other one. Otherwise, we call them conflicting . The segments we introducecan overlap and there is no restriction on the number of segments or the length of each segment.However, we would like to minimize the maximum number of segments that cover a cell.After we introduce the segments, an adversary puts a non-negative number on each cell of thegrid. We emphasize that our segments do not depend on these numbers, as the numbers are givenafter we provide our segments. The score of a subset of cells in the table is the sum of the values inthe cells, and the overall score of the table is the maximum score of a path of length 2 m − α ≥ β ≥
1, we call asolution ( α, β )-approximate if at most α segments cover each cell and it guarantees a 1 /β fractionof the score of the table for us for any assignment of numbers to the table cells. We show in Section4 that grid packing admits an ( O ( m κ log m ) , O (1 /κ ))-approximate solution for any 0 < κ < LIS . Let us consider an array a of length n . We assume for the sake of this example thatall the numbers of the array are distinct and are in range [1 , n ]. In other words, a is a permutationof numbers in [ n ]. We map the array to a set of points on the 2D plane by putting a point at ( i, a i )for every position i of the array.Now, divide the plane into an m × m grid, and fix a longest increasing subsequence. The numberon each cell of the grid would be equal to the contribution of the elements in that grid cell to thefixed longest increasing subsequence. (We emphasize that the number is not the longest increasingsubsequence inside the cell, but the contribution to the fixed longest increasing subsequence only.)It follows that the score of the grid is exactly equal to the size of the longest increasing subsequence.Let us assume that the score of each segment is available. To approximate the score of the grid(which equals the size of the LIS ) we find the largest score we can obtain using non-conflictingsegments by dynamic programming. The last observation which gives us speedup for
LIS is thefollowing: instead of using the score of each segment (which we are not aware of), we use the sizeof the
LIS for each segment as an approximate value for its score.
LIS of each segment can becomputed in time ˜ O ( n/m ) since at most n/m elements appear in every row or every column ofthe grid. This quantity is clearly an upper bound on the score of each segment but can be usedto construct a global solution for the entire array (see Section 5 for more details). In our dynamicalgorithm, every time a change is made, we only need to update the approximate score ( LIS ) of the6 , , , , , , , , i h , , , , , , , , i is mapped to the 2D plane.corresponding segments.Our solution for grid packing is based on a combinatorial construction. The first observation isthat any path of length 2 m − array packing , asfollows. For the array packing problem, an array of length m is given as input (with no numbers onit). Our goal is to define segments (this time all horizontal), while keeping the maximum numberof segments covering each cell small. After we fix our solution, the adversary puts non-negativenumbers on the array cells. For any fixed interval [ x, y ] we would like to have a segment completelyin that interval whose score is at least a fraction of the score of that interval. More precisely, asolution for array packing is ( α, β )-approximate if it covers each cell at most α times and the scoreof any interval over the maximum score of a segment inside it is bounded by β . Similar to gridpacking, we are not aware of the numbers when giving a solution, and the adversary is aware of oursolution before deciding which numbers to put and which interval to choose for the comparison.An ( α, β )-approximate solution for array packing yields a (2 α, β )-approximate solution for gridpacking as follows. We treat each row and each column of the grid as an array and make a separatesolution for the corresponding array packing instance. After the adversary puts the numbers onthe grid, any path from bottom left to the top right can be divided into disjoint column intervals orrow intervals, one of which provides us a 2 approximate solution for the score of the grid. Finally,the guarantee of array packing enables us to prove that the above solution is (2 α, β )-approximatefor grid packing.Thus, all that remains is to provide a solution for array packing. To begin, for each cell of thearray, there should be one segment covering only that cell. Otherwise, there is no way to competewith an adversary that puts 1 on that cell and 0 on the other cells and uses that cell for the chosen7 , , , , , , , , i h , , , , , , , , i is mapped to the 2D plane. An LIS is shown by greenpoints. The plane is divided into a 3 × LIS . The score of the grid is equal to the
LIS of the array. The scoreof the grid is made by the path colored in green.interval. Thus, m segments of length 1 for the m cells of the array is an inevitable part of anysolution. A first idea to extend this construction is to put segments of length 2 on every other cellof the array, giving m/ ≤ i ≤ log m , we use m/ i segments of length 2 i to cover all cells of the array. While with thisconstruction at most log m segments cover each cell, the best guarantee that we can expect for sucha solution in terms of score is a 1 / Ω(log m ) fraction of the score of each interval. That is, such asolution is only ( O (log m ) , O (log m ))-approximate.To improve the approximation factor to a constant, we make m κ copies of each set of segments.Roughly speaking, for segments of length 2 i we make m κ copies by right shifting the segments by2 i /m κ cells each time (see Section 4 for more details about this construction and edges cases suchas when 2 i < m κ ). This clearly adds a multiplicative overhead of m κ for the number of segmentscovering each cell. However, as we show in Section 4 it improves the second parameter of theapproximation guarantee down to O (1 /κ ) from O (log m ). Theorem
6, [restated informally].
For any < κ < , the grid packing problem on an m × m gridadmits an ( ˜ O ( m κ ) , O (1 /κ )) -approximate solution. Grid packing is a very strong tool for approximating
LIS . For example, consider an array a oflength n for which we wish to design a block-based dynamic algorithm for LIS . We fix a constant0 < κ < f ( n ) = ˜ O ( n κ ). Let m = n / be the size of the grid we construct for this array.The horizontal thresholds are set in a way that separate the elements into m different pieces eachcontaining roughly n/m elements. That is, the first threshold is the value of the n/m ’th elementof the array after sorting the numbers and so on. The vertical thresholds are set to divide the8igure 4: Each path from bottom-left to top-right is divided into disjoint row-intervals or column-intervals. Row intervals are shown with orange and column intervals are shown with blue. All rowintervals are non-conflicting and all column-intervals are also non-conflicting.elements into m different parts each containing n/m elements. That is, the first part contains thefirst n/m elements of the array and so on. This way, each element of the array corresponds to oneunique cell of the grid.The most important property of this division is that every row or every column of the gridcontains at most n/m elements. This property is asymptotically maintained for the next g ( n ) = n / operations for which the block-based algorithm is responsible. Obviously, this guarantee also holdsfor the segments. We solve the problem in the following way: first we make a solution for gridpacking of size m × m . For each segment, we make a separate instance of the dynamic LIS problemthat solves the problem for the elements covered by that segment. Initially, we use the naivealgorithm that computes
LIS from scratch every time an operation arrives. However, since eachsegment corresponds to at most O ( n/m ) elements, the worst-case update time for each segment is˜ O ( n/m ). Moreover, each cell is covered by at most ˜ O ( m κ ) segments which means each operationmodifies at most ˜ O ( m κ ) segments. Thus, the total update time is ˜ O ( m κ n/m ) = ˜ O ( n / κ ). Inorder to approximate the size of the LIS , every time we run a DP on the segments to find a setof non-conflicting segments whose total size of
LIS is maximized. Notice that the
LIS of eachsegment is available in time O (1) (since after each update we store the size of the solution foreach segment), and DP takes time ˜ O ( m κ ) which is basically the total number of segments wehave. This is obviously a lower bound on the actual solution size since any partial solution for anon-conflicting set of segments can be combined to obtain a global solution for the union of theelements in all segments. Moreover, the size of the LIS for each segment is definitely an upperbound on the contribution of that segment to the optimal solution. Thus, the solution of the DPis at least an Ω( κ ) fraction of the size of the LIS for the entire array.One thing to keep in mind is that updating the grid requires a more careful analysis. Since thecolumn divisions are based on the indices of the elements, when we add or remove some elements,some columns may grow wider or thinner. While the grid illustration may make it seem challengingto manage such update operations, the actual implementation is straightforward. We define m − n/m . Every time an element is added or removed, in addition toupdating the binary tree data structure tracking the location of each element, we can also updatethe thresholds separating the grid into subgrids..Since the preprocessing time is ˜ O ( n κ ) and we run the algorithm for n/m = O ( n / ) stepsand the worst-case update time for each operation is ˜ O ( n / κ ), this block-based algorithm can beturned into a dynamic algorithm for LIS with approximation factor O (1 /κ ) and worst-case updatetime ˜ O ( n / κ ). While this is worse than the solution given in Corollary 4 both in terms of the9pproximation factor and worst-case update time, this solution can be extended to improve theupdate time down to ˜ O ( n ǫ ) for any constant ǫ >
0. All it takes to improve the update time is toreplace the naive
LIS algorithm of each segment by the more clever algorithm we explained above.While this comes at the expense of a larger approximation factor, the worst-case update timeimproves. We show in Section 5 that by setting κ = Ω( ǫ ) and recursing on this algorithm O (1 /ǫ )times we obtain a dynamic algorithm for LIS with worst case update time ˜ O ( n ǫ ) and approximationfactor O ((1 /ǫ ) O (1 /ǫ ) ). Theorem
9, [restated informally].
For any constant ǫ > , there exists an algorithm for dynamic LIS whose worst-case update time is ˜ O ( n ǫ ) and whose approximation factor is O ((1 /ǫ ) O (1 /ǫ ) ) . It follows from Theorem 9 that after reporting the estimated value of the solution, we canalso determine the corresponding sequence in time proportional to its size. More precisely, afterusing DP to construct a global solution based on partial solutions of the segment, we can find outwhich segments contribute to such a solution and recursively recover the corresponding increasingsubsequences of the relevant segments. To this end, in addition to the DP table which we use forconstructing a global solution, we also store which segments contribute to such a solution. Thisway, the runtime required for determine the corresponding increasing subsequence is proportionalto the size of the solution.
Remark 2.
After reporting a solution of size x by our dynamic LIS algorithm, our algorithm isable to report an increasing subsequence of length x in time O ǫ ( x ) . For the special case of
LIS + where only insertion operations are supported, we improve theapproximation factor down to O (1 /ǫ ). Moreover, if one favors the update time over the approx-imation factor, we show that the update time can be reduced to polylogarithmic if we allow theapproximation factor to be O (log n ). To illustrate the effectiveness of the grid packing technique, we bring yet another example, thistime in the context of streaming algorithms. It has been shown that
LIS can be approximatedwithin a factor of 1 + ǫ in the streaming model with memory O ( √ n ) [17]. Moreover, matchinglower bounds are also provided by G´al and Gopalan [14]. They show that it is impossible to beatthe Ω( √ n ) barrier with any deterministic algorithm that runs in a constant number of rounds andobtains a constant factor approximation. We show that this can be improved with a randomizedalgorithm that reads the input in a particular order. This notion is called advisory help and hasbeen previously studied [8] to provide graph algorithms in the streaming model.In such a setting, we design a streaming algorithm but we ask the adversary to give us the inputin a particular order. To avoid losing information, elements come in the form ( i, a i ) which specifiesboth the position and the value of each element. We show that in three rounds we can obtain an O (1 /κ ) approximation with memory ˜ O ( n / κ ). Roughly speaking, in the first round we sample m = n / elements from the array and we set horizontal lines of the grid based on their values.Vertical lines just evenly divide the elements based on their indices into portions of size n/m .In the second round, we ask the adversary to give us the elements of the array but in the roworder (shown in Figure 5). In this round, we compute the solution for horizontal segments. Eachsegment contains at most ˜ O ( n/m ) = ˜ O ( n / ) element with high probability and therefore using10 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25 1 6 11 16 212 7 12 17 223 8 13 18 234 9 14 19 245 10 15 20 25Figure 5: Order of the ways that the elements of the array are given to us are shown in this figure.Figure on the left shows the order of elements in the second round and the figure on the right showsthe order of the element in the third round.the algorithm of [17] we can approximate its LIS within factor 1 + ǫ with memory ˜ O ( n / ). Sinceeach cell is covered by at most ˜ O ( m κ ) segments, at each step we solve the problem for at most˜ O ( m κ ) segments simultaneously which adds an overhead of ˜ O ( m κ ) = ˜ O ( n κ ) to the memory of thealgorithm. Thus the overall memory is bounded by ˜ O ( n / κ ). The third round solves the problemfor vertical segments similar to the horizontal ones. The only difference is that this time we askthe adversary to give us the elements in the column order. Once all the solutions for all segmentsare available, we run a DP with memory ˜ O ( m κ ) = ˜ O ( n / κ ) to approximate the final solutionsize. Notice that this solution is not refuted by the impossibility result of [17] since it both usesrandomization and extra help from the adversary. In order for the adversary to provide us thearray elements in this particular order, she may need to sort the numbers based on their values.However, sorting does not overly simplify the problem. Computing the LIS of an array is equallyhard if the elements are given in the sorted order!
Additionally, we present a dynamic algorithm for
DTM . Distance to monotonicity seems to bemore tractable than
LIS since previous work obtain much more efficient algorithms for
DTM than
LIS [2, 17, 29]. In particular, there are several known techniques for approximating
DTM within aconstant factor. As an example, one can model the problem with a graph containing n vertices eachcorresponding to an element. There is an edge between two vertices, if the corresponding elementsare not increasing. While in this interpretation, LIS is equivalent to the largest independent setof the graph,
DTM translates to vertex cover which can be approximated within a factor of 2 bymaintaining a maximal matching. As part of our algorithm, we show that such a maximal matchingcan be maintained with worst-case update time O (log n ) which yields a dynamic algorithm for DTM with approximation factor 2 and worst-case update time O (log n ).However, we further strengthen this result by improving the approximation factor down to 1 + ǫ while keeping the update time intact. The heart of our improvement is based on an exact algorithmfor computing DTM when an approximate solution is available. We show in Section 6 that givenrandom access to the elements of an array a of size n and a constant approximate solution of size k for the array, one can compute an exact solution for DTM in time O ( k log n ). Just knowing thesize of the approximate solution does not suffice here; our algorithm requires random access to theelements of the approximate solution as well. 11 emma
11, [restated informally].
Let a be an array of length n and S be a set of k elements whoseremoval from a makes a increasing. One can compute the distance to monotonicity of a in time O ( k log n ) . The above algorithm, in addition to the 2-approximate solution, yields a 1 + ǫ approximationblock-based algorithm for DTM . Starting from an array a and provided access to a 2-approximatesolution, we set f ( a ) = ˜ O ( k ) where k is the size of the approximate solution. Here, f, g, and h donot depend on n since the runtimes depend on the solution size. See Section 3 for more information.Moreover, g ( a ) = kǫ/ h ( a ) = O (1). After computing an exact solution via the algorithm ofLemma 11 in the preprocessing phase, we keep reporting d + i as an estimate for DTM for the i ’thoperation where d is the solution for the initial array. The block-based algorithm then can be usedto obtain a dynamic algorithm with worst-case update time O (log n ). Theorem
14, [restated informally].
For any constant ǫ > , there exists an algorithm for dynamic DTM whose worst-case update time is O (log n ) and whose approximation factor is ǫ . Although our method is simple, it has a nice implication for classic algorithms. We show thatusing Lemma 11, we can approximate
DTM in time O ( n ) within an approximation factor 1 + ǫ (alog is shaved from the runtime by incurring a factor 1 + ǫ to the approximation guarantee). Thisresult is tight in two ways: i) Any constant factor approximation algorithm for DTM has to makeat least Ω( n ) value queries to the elements of the array to solve the case that the solution is either0 or 1. ii) Any exact solution which is comparison based or based on algebraic decisions trees hasa runtime of at least Ω( n log n ) [13, 31].To achieve this, we first compute a 2-approximate solution for DTM in time O ( n ) (see SectionC for more details). If the size of the solution is smaller than √ n , we use the algorithm of Lemma11 to obtain an exact solution in linear time. Otherwise, we use the algorithm of [29] to obtain a1 + ǫ approximate solution in time O ( n ) . The runtime of the algorithm given in [29] is ˜ O ( n/d + √ n ) when the solution size is lower bounded by d . From Amortized Update Time to Worst Case Update Time
The goal of this section is to show a reduction that simplifies the problem with respect to worst-casetime constraints. Ultimately, in our algorithms, we prove that the update time of each operationis bounded in the worst case. However, it is more convenient to allow for larger update times insome cases, while keeping a bounded amortized update time. In this section, we prove that if ouralgorithms adhere to a certain structure, then worst-case update time reduces to amortized updatetime. Later in the section, we present a motivating example to show how the reduction enablesus to simplify the proofs. In our example, we seek to design a 1 + ǫ approximation algorithm fordynamic LIS with worst-case update time ˜ O ( √ n ).In our framework, we start with an array a of size n and our algorithm is allowed to makea preprocessing of time f ( a ). For the next g ( a ) steps, the processing time of each operation isbounded by h ( a ) in the worst case. After g ( a ) steps, our algorithm is no longer responsible forthe operations and terminates. We refer to such an algorithm as block-based . Note f ( a ), g ( a ), and h ( a ) are not necessarily determined based only on the size n of the array a . For example, in thealgorithm of Section 6, the values of these functions are proportional to the solution size for a ,not n . However, when these functions are only dependent on n , we may drop a in the notationand use n instead. Functions f, g, and h should meet one important property: after applying g ( a )arbitrary operations to an array a and obtaining a new array a ′ , f ( a ′ ) , g ( a ′ ) and h ( a ′ ) should notchange asymptotically. More specifically, although the reduction holds when the values are withinany constant factor, we assume 1 / ≤ f ( a ) /f ( a ′ ) , g ( a ) /g ( a ′ ) , h ( a ) /h ( a ′ ) ≤
2. We call this property relativity . We also assume without loss of generality that f, g, and h are always lower bounded bya constant (say 20) and when the array size is constant, so are the values for f ( a ) , g ( a ) , and h ( a ).We show in the following that a block-based algorithm A for LIS or DTM with identifiers h f, g, h i can be used as a black box to obtain a dynamic algorithm A ′ with worst-case update time O (max { h ( a ) , f ( a ) /g ( a ) } ). The approximation factor of the algorithm is preserved in this reduction.To show a use case of this technique, we provide a simple analysis of a (1 + ǫ )-approximate dynamicalgorithm for LIS with worst-case update time ˜ O ( √ n ). Lemma 2.
Let A be a block-based algorithm with preprocessing time f ( a ) that approximates dy-namic LIS or dynamic
DTM for up to g ( a ) many steps with worst-case update time h ( a ) . If h f, g, h i satisfies relativity then there exists a dynamic algorithm A ′ for the same problem whose worst-caseupdate time is bounded by O (max { h ( a ) , f ( a ) /g ( a ) } ) and whose approximation factor is the sameas A .Proof. Figure 6 gives a pictorial depiction of the proof idea. We construct an algorithm A ′ in thefollowing way: A ′ uses algorithm A repeatedly. To distinguish between multiple instances of A , weadd subscripts; the first time we use algorithm A we call it B . Every B i is basically a copy of theblock-based algorithm A which is modified slightly to execute the preprocessing part in multiplesteps. We begin with using our block-based algorithm B at step 1. At this point we call the initialarray (which is empty) a (1) . Since the size of the array is constant, so is the preprocessing timeand therefore we can ignore it when bounding the time complexity. For g ( a (1) ) many steps, we usealgorithm B to preserve an approximate solution and from then on, we use a separate algorithmfor the rest of the operations, namely B . The construction of B is given below:When B has gone 9 /
10 of the way and is only responsible for g ( a (1) ) /
10 more operations,we initiate algorithm B . Let a (2) be the array at this point. B needs to run the preprocessingstep which requires f ( a (2) ) many operations. This may not be possible in a single step, therefore,13 a (1) B B . . . preprocessingupdating two operations in each step g ( a (1) ) / g ( a (2) ) / a (2) a (3) g ( a (1) )10 g ( a (1) ) g ( a (1) )10 + g ( a (2) ) g ( a (1) )+ g ( a (2) ))10 Figure 6: The reduction is shown in this figure.we break the computation into g ( a (1) ) /
20 pieces and execute each piece in the next g ( a (1) ) / g ( a (1) ) /
20 steps operations that arrive after the construction of B are processed: two operations in each step. While this is happening, algorithm B processesthe operations and updates the solution size. When we reach g ( a (1) ) /
10 many steps after theconstruction of B , algorithm B has already finished the preprocessing and all the operations thathave arrived so far are applied to it. This is exactly the time that B terminates, and from thenon, we use algorithm B to process each operation.Similarly, B is constructed when B has applied g ( a (2) )9 /
10 operations. This construction goeson as long as operations arrive.The correctness of A ′ follows from that of A . Therefore, any approximation factor that A guarantees for us also carries over to A ′ . For the update time, the construction guarantees that atevery time, at most two instances of algorithm A are active. At every step, in each algorithm, weeither perform an operation or we are initializing the algorithm in which case the update time isbounded by O (max { f ( a ) /g ( a ) , h ( a ) } ).One thing to keep in mind in the above argument is that because of relativity the value offunctions f, g, and h remain asymptotically the same during two consecutive runs of algorithm A .Thus, g ( a ) is within a constant factor for two consecutive runs of A and therefore f ( a ( i ) ) /g ( a ( i − )is asymptotically the same as f ( a ( i ) ) /g ( a ( i ) ).We emphasize that there is a constant-factor overhead in the update-time of the reduction whichis hidden in the O notation.To illustrate the effectiveness of our reduction, we bring a motivating example to show how itsimplifies the design of dynamic algorithms for LIS . LIS
The reduction of Section 3 gives us a very convenient framework to design dynamic algorithms for
LIS and
DTM . Here we bring a simple block-based algorithm for dynamic
LIS with approximationfactor 1 + ǫ that results in an algorithm with the same approximation factor and worst-case updatetime ˜ O ( √ n ).Since in the following, functions f, g , and h only depend on the size of the array in this case,we write them in terms of n . 14 emma 3. For any ǫ > , there exists a block-based algorithm for LIS with approximation factor ǫ , preprocessing time f ( n ) = ˜ O ( n ) and update time h ( n ) = ˜ O ( √ n ) that maintains an approximatesolution to LIS for up to g ( n ) = √ n many operations.Proof. In the preprocessing phase, we first compute the longest increasing subsequence in time˜ O ( n ). Let the solution size be r . Based on the value of r , we consider two different strategies:If r is already at least 2 √ n/ǫ , in the next √ n steps, we do not make any changes to the arrayand output r − i after i ’th operation. Since each operation hurts the solution size by an additivefactor of at most 1, our solution is always valid and has approximation factor 1 + ǫ throughout thisprocess.Otherwise, we use the algorithm of Chen et al. [7] to update the solution in every step. Thesetup cost for the algorithm of Chen et al. [7] is ˜ O ( n ) which can be executed in the preprocessingstep (since this is not explicitly mentioned in [7], we bring more details about their algorithm inAppendix D). Moreover, the solution size is initially upper bounded by 2 √ n/ǫ and it can grow toat most 2 √ n/ǫ + √ n after √ n operations. Therefore, the update time remains ˜ O ( √ n ) in the worstcase.Based on Lemma 2, a dynamic algorithm for LIS can be implemented with worst-case updatetime ˜ O ( √ n ) and approximation factor 1 + ǫ . Theorem 4. [a corollary of Lemmas 2 and 3] For any constant ǫ > , there exists a dynamicalgorithm for LIS with approximation factor ǫ and update time ˜ O ( √ n ) in the worst case. Grid Packing
This section is dedicated to a combinatorial problem which we call grid packing . Definitions aregiven in Section 2 but for the sake of completeness we restate them here. In this problem, we havea table of size m × m . Our goal is to introduce a number of segments on the table. Each segmenteither covers a consecutive set of cells in a row or in a column. A segment A precedes a segment B if every cell of A is strictly higher than every cell of B and also every cell of A is strictly tothe right of every cell of B . Two segments are non-conflicting , if one of them precedes the otherone. Otherwise, we call them conflicting . The segments we introduce can overlap and there is norestriction on the number of segments or the length of each segment. However, we would like tominimize the maximum number of segments that cover each cell.Figure 7: Segments are shown on the grid. The pair (black, orange) is conflicting since the yellowcell (covered by the black segment) is on the same row as the blue cell (covered by the orangesegment). The following pairs are non-conflicting: (green, black), (green, orange), (green, blue),(red, orange), (red, blue), (black, blue).After we choose the segments, an adversary puts a non-negative number on each cell of thegrid. The score of a subset of cells of the table would be the sum of their values and the overallscore of the table is the maximum score of a path of length 2 m − α, β )-approximate, if at most α segments cover each cell and it guarantees a 1 /β fraction of the score of the table for us for anyassignment of numbers to the table cells.In this section, we prove the following theorem: For any grid m × m and any 0 < κ <
1, thereexists a grid packing with guarantee ( O ( m κ log m ) , O (1 /κ )). That is, each cell is covered by at16023 1150 103 0210 1Figure 8: After we introduce the segments (left figure), the adversary puts the numbers on thetable (middle figure). In this case, the score of the table is equal to 12 (via the path depicted onthe right figure), and our score is equal to 9 obtained from two non-conflicting segments green andblue.most O ( m κ log m ) segments and the ratio of the table’s score over our score is bounded by O (1 /κ )in the worst case. This solution is constructive and our proof also gives us the segments. We first consider a useful sub-problem, array packing. Array packing is a one-dimensional variantof grid packing, where we have an array of size m and we choose segments of consecutive cells inthis array. Again segments can overlap and there is no constraint on the number or size of thesegments; after we fix the segments an adversary puts non-negative numbers on the array cells; andthe score of a subset of the array cells would be the sum of their values. Here we call a solution( α, β )-approximate if no more than α segments cover each cell and for any interval [ x, y ] of thearray, there exists a segment which completely lies in this interval with a score is at least a 1 /β fraction of the overall score of the interval.Figure 9: A (3 , / m , for any 0 < κ <
1, there exists a solution for arraypacking with approximation guarantee ( O ( m κ log m ) , O (1 /κ )). We then use this in a solution forgrid packing.We construct two sets of segments in the following way: let d be the largest power of 2 suchthat d ≤ m κ . In the first set, for any 1 ≤ i ≤ d and any 1 ≤ j ≤ m − i + 1 we introduce a segmentstarting from cell j and ending at cell i + j − ≤ i ≤ log m and any j divisible by 2 i such that j + d i − ≤ m ,we introduce a segment that spans the interval [ j, j + d i − Lemma 5.
For any m ≥ and any < κ < there exists a solution for the array packing problem ... d Figure 10: In the first set, from each cell we introduce d segments with lengths 1 , , . . . , d . . . .d i d i d i d i d i i ... . . . . . .d Figure 11: In the second set, for each i , there is a segment of length d i starting from any cellwhose starting point is divisible by 2 i . The distance between consecutive segments is 2 i . of size m with approximation guarantee ( O ( m κ log m ) , O (1 /κ )) . Proof.
The solution is the union of the two sets of segments described above. The key to showingit gives the required approximation is the following: For each interval [ x, y ] we can cover the entireinterval with O (1 /κ ) segments that completely lie in the interval [ x, y ]. Therefore, no matter howthe adversary puts the numbers on the cells, the summation of the scores for such segments is atleast as much as the score of interval [ x, y ] and thus one of those segments has an Ω( κ ) fraction ofthe score of interval [ x, y ]. To show this, we cover the cells of the intervals in the following way.If y − x < d , then we can cover the entire interval with a single segment (of the first type) andthe proof is trivial. Otherwise, we only use the segments of the second type in our covering. Let q be the size of the largest segment that completely lies in the interval [ x, y ].We start with an empty set S ℓ and a pointer p ℓ initially equal to x . Each time we find a segment18hat starts in the range [ x, p ℓ ] and ends in the range [ x, y ]. If many such segments exist, we choosethe one with the right-most ending point and in case of a tie, we break the tie arbitrarily. We addthe new segment to S ℓ and continue the process by increasing p ℓ to the cell right after the newsegment ends. We continue this process so long as p ℓ − x < q/d We repeat the same process but this time starting from p r = y and proceeding backwards.Initially we set S r to be an empty set. Every time, we find a segment that ends in range [ p r , y ]and starts in range [ x, y ]. Similarly, when multiple options are available, we choose the one whosestarting point is the smallest. We add the new segment to S r and update p r to be the right-mostcell not covered by the new segment. We terminate this process when y − p r ≥ q/d .Obviously segments in S ℓ ∪ S r cover both intervals [ x, p ℓ −
1] and [ p r + 1 , y ]. If p r < p ℓ then theentire interval [ x, y ] is covered. Otherwise, we can add two more segments of size q to fill the gap.More precisely, we add the left-most and right-most segments of length q that lie completely in theinterval [ x, y ]. The analysis is based on the following property of our construction: the distancebetween consecutive segments of length q is bounded by q/d . Thus, after putting such segmentson the interval [ x, y ], each cell is covered except the ones whose distance to one of the end pointsis smaller than q/d . However, segments of sets S ℓ and S r cover those cells.We show that | S ℓ | , | S r | ≤ O (1 /κ ). To this end, we prove that every time we add a new segmentto S ℓ , the size of the new segment is at least d times larger than the size of the previous segmentwe added to S ℓ . The reason is the following: let l be the length of the segment we add to S ℓ atsome point. This means that after adding this segment to S ℓ we have p ℓ ≥ x + l . l is a power of 2since we only use the segments of the second type. Moreover, one cell in this range is divisible by l which means that it is the starting point of another segment of length dl . Thus the next segmentthat we add to S ℓ has a length at least dl which is d times larger than the current one. Therefore,the size of | S ℓ | is bounded by log d m = O (1 /κ ). The same also holds for S r . x yqq ≥ q/d ≥ q/d < q/d < q/d Figure 12: Green parts are covered with segments in S ℓ and blue parts are covered by segments in S r . Two segments of length q cover the rest of the elements.All that remains is to show that each cell of the array is covered by at most O ( m κ log m )different segments. In the first set, the length of each segment is bounded by d and therefore thereare at most d different combinations for the starting and ending cells of the intervals that cover aparticular cell. Since d ≤ m κ , this guarantee is met by the first set of segments. For the secondset, notice that there are at most O (log m ) distinct segment sizes. Moreover, each cell is covered byat most d segments of a particular size. Thus, each cell is covered by at most O ( d log m ) differentsegments of the second set which is bounded by O ( m κ log m ).19 .2 An ( O ( m κ log m ) , O (1 /κ )) -approximate Solution for Grid Packing We provide a reduction from grid packing to array packing. The intuition behind the reduction isgiven below: Let us fix a path from the bottom-left to the top-right of the array. We can dividethe cells of the path into some disjoint vertical and horizontal intervals as show in Figure 13. Inthis decomposition, all the row-intervals are non-conflicting and all the column-intervals are alsonon-conflicting (row-intervals and column-intervals may be conflicting).Figure 13: Each path from bottom-left to top-right is divided into disjoint row-intervals or column-intervals. Row intervals are shown with orange and column intervals are shown with blue. All rowintervals are non-conflicting and all column-intervals are also non-conflicting.For any path and any combination of numbers on the cells of the path, either the sum of thenumbers on the row-intervals or the sum of numbers on the column intervals is at least a 1 / Theorem 6.
For any < κ < , the grid packing problem on an m × m grid admits an ( O ( m κ log m ) , O (1 /κ )) -approximate solution.Proof. We treat every row and every column of the grid as an array of length m and construct an( O ( m κ log m ) , O (1 /κ ))-approximate solution of the array packing problem for that row or column(Lemma 5). With this construction, every cell is covered by at most O ( m κ log m ) segments, becauseevery cell is covered by at most O ( m κ log m ) horizontal segments and every cell is covered by atmost O ( m κ log m ) vertical segments, so the total number of segments covering each cell is boundedby O ( m κ log m ).After the adversary puts the numbers on the cells of the grid, the score of the grid equals thelargest score of a path of the length 2 m − O (1 /κ ) and fits completely within that interval. Since all the row-intervalsare non-conflicting, these segments are non-conflicting, and the score of those segments is at leastan O (1 /κ ) fraction of the score of the row intervals, which is at least 1 / Constant Factor Approximation for
LIS with Update Time ˜ O ( n ǫ ) In this section, we show that for any constant ǫ >
0, there is a dynamic algorithm for
LIS that losesonly a constant factor in the approximation (where the constant depends on ǫ ) and guarantees anupdate time bounded by ˜ O ( n ǫ ). Our algorithm is based on the grid packing technique explainedin Section 4.We begin by explaining a simple algorithm for dynamic LIS where the approximation factoris constant and the update time is close to ˜ O ( n / ). This result is weaker than what we give inSection 3 both in terms of update time and approximation factor, but we show this new techniquecan be extended to obtain the result for any ǫ > O ( n ) is trivial; wecompute the LIS from the scratch after each operation arrives. We call this algorithm A ′ . From A ′ , we make a block-based algorithm A and then turn it into an algorithm A ′ with worst-caseupdate time ˜ O ( n / κ ) for a small enough κ > a of length n . Map the elements of a ontothe 2D plane by creating a point ( i, a i ) for every element of the array. Recall that we assume theelements are distinct but there is no bound on their values. Define m = n / and construct a gridin the following way: draw m − n is not divisible by m ,some parts may have one more point than other parts. Similarly, we draw m − m parts each having either ⌊ n/m ⌋ or ⌈ n/m ⌉ points. This gives an m by m grid, with each grid cell corresponding to a “rectangle” in the 2D plane.0 1 2 3 4 5 6 7 8 900123456789 0 1 2 3 4 5 6 7 8 900123456789 10(7 , , | , , | , ,
8) (7 , , | , , , | , , It will be clear to the reader later in the section why we use such an unconventional notation for this algorithm. < κ < O ( m κ log m ) , O (1 /κ )) for the m by m grid. Each element ofthe array lies in exactly one cell of the grid and corresponds to all segments that cover that cell.Next for each segment in the solution of grid packing, we construct a separate instance of the LIS problem that maintains a solution for the
LIS of the corresponding elements.Each time an operation arrives, we update the solution for the corresponding segments. Letus be more specific about this. Initially, m − n/m . As operations arrive, the elements are shifted to the left or to the right (their indicesare updated). Each vertical line can be thought of as a separator between two consecutive elementsthat is also shifted to the left or to the right when elements are added or removed. Thus, althoughthe vertical lines move, each element which is inserted or deleted lies between two thresholds andcorresponds to a unique column of the grid. The corresponding row is uniquely determined by thehorizontal lines (those lines remain unchanged). Thus, every element insertion or deletion affectsonly one cell of the grid which is covered by a bounded number of segments. When the size ofthe LIS is desired, we run a dynamic program and find a subset of non-conflicting set of segmentswhose total solution size is maximized. We show that this gives us approximation factor O (1 /κ )for the LIS of the array. Our algorithm is responsible for up to g ( n ) = n / many operations.0 1 2 3 4 5 6 7 8001234567890 1 2 3 4 5 6 7 8 900123456789 h , , | , , | , , i h , , | , | , , i Figure 15: An example for removing an element from the array.
Lemma 7.
Let < κ < be an arbitrarily small constant used for the solution of grid packing. A is a block-based algorithm for dynamic LIS with approximation factor O (1 /κ ) whose preprocessingtime is ˜ O ( n κ ) and whose update time is ˜ O ( n / κ ) . Moreover, A runs for n / many steps.Proof. We first prove that the preprocessing time of A is ˜ O ( n κ ). It takes time ˜ O ( n ) to sort thenumbers and draw the grid lines. Also, the runtime for constructing the solution for grid packing is22 O ( m κ ), which is smaller than ˜ O ( n ). Every cell of the grid is covered by at most ˜ O ( m κ ) differentsegments. We construct a separate LIS instance for every segment. Each grid cell appears in atmost ˜ O ( m κ ) segments. Therefore, every element of the array in included in in at most ˜ O ( m κ ) LIS instances. Thus, the total size of all the instances combined is bounded by ˜ O ( nm κ ) and thusfinding an LIS for each segment takes time ˜ O ( nm κ ) in total. Since m = n / the preprocessing timeis bounded by ˜ O ( n κ/ ) = ˜ O ( n κ ).The total number of points in every column, or every row of the grid is bounded by ⌈ n/m ⌉ = O ( n / ). Thus, the size of the LIS instance for each segment is also bounded by O ( n / ). Since werun the algorithm for at most O ( n / ) many steps, the sizes of the LIS instances remain boundedby O ( n / ) even if we add more numbers to them in the next O ( n / ) many operations.When a new operation arrives, this only affects one cell of the grid which we can find usingits position and its value. We update all the corresponding segments that cover that cell. Theircount is bounded by ˜ O ( m κ ) ≤ ˜ O ( n κ ). Moreover, each one we can update in time ˜ O ( n / ) since theproblem size for each segment is bounded by O ( n / ). Every time the size of the LIS is desired,we run a DP in time ˜ O ( m κ ) and find a solution that can be constructed using non-conflictingsegments. The size of the LIS for each segment is available in time O (1). Thus, the runtime forapproximating the LIS is bounded by ˜ O ( m κ ) ≤ ˜ O ( n / κ ). Therefore, the update time h ( n ) isbounded by ˜ O ( n / κ ) for every operation.For the dynamic program, we define an m × m table D such that D [ i ][ j ] denotes the solutionfor any subset of non-conflicting segments in the first i rows and the first j columns of the grid.Obviously D [ i ][ j ] ≥ D [ i − j ] , D [ i ][ j − D [ i ][ j ], we startby assigning max { D [ i − j ] , D [ i ][ j − } to it. Next, for any segment that ends at cell ( i, j ), weupdate D [ i ][ j ] as D [ i ][ j ] = max { D [ i ][ j ] , D [ i ′ − j ′ −
1] + w } where ( i ′ , j ′ ) are coordinates of the bottom-left corner of the segment and w is the length of its LIS .The total runtime of this algorithm is asymptotically equal to the number of segments on the grid.Finally, we show that this gives us an O (1 /κ )-approximate solution for the LIS of the entirearray. For any point in time, fix an arbitrary solution of the longest increasing subsequence for thearray at that time. Assume that the numbers the adversary puts on the cells of the grid are thecontributions of the cells to the fixed longest common subsequence. This way, the score of the gridis exactly equal to the size of the longest increasing subsequence.In addition to the above, the score of every segment is a lower bound on the
LIS of the elementsfor that segment. Thus, by the guarantee of the grid packing solution, the solution we obtain byappending the solutions of non-conflicting segments is definitely an O (1 /κ ) approximate solutionfor the score of the grid which is the size of the solution. Finally, the validity of our solution followsfrom the fact that since all the segments are non-conflicting, then we can combine their partialsolutions and that gives us a valid increasing subsequence.Keep in mind that when we add elements to or remove elements from the array, the indices ofthe numbers change. Thus, we need to also update the coordinates of the vertical lines. This canbe done similarly to the way we update the indices of the array elements. Therefore, this does notadd computational difficulty as all we need to know for each new operation is which column of thegrid this operation applies to and which row of the grid is affected by the new operation. Also, foredge cases (when the left most or right most element of a column is removed or added), we have achoice of which column we add the new points to. In any case, the solution we find preserves theapproximation. 23ne thing to note about the algorithm of Lemma 7 is that by setting κ arbitrarily close to 0,we can obtain a update time close to ˜ O ( n / ). By Lemma 2, algorithm A can be turned into analgorithm A ′ with the same approximation factor but worst-case update time ˜ O ( n / κ ). Although A ′ has an approximation factor of O (1 /κ ), its update time is ˜ O ( n / − κ ) times smaller than thatof A ′ . Thus, our approach to improve the overall update time is to replace A ′ by A ′ to obtaina faster (but worse in terms of approximation factor) algorithm. Lemma 8 (as a corollary of Lemmas 7 and 2) . For any < κ < , there exists a dynamic algorithmfor LIS with worst case update time ˜ O ( n / κ ) and approximation factor ˜ O (1 /κ ) . It is not hard to see that one can recurse on the above idea to improve the update time. Thiscomes however, at the expense of a larger approximation factor. We prove in Theorem 9 that,similar to what we did for Lemma 7, one can devise an algorithm with worst-case update time˜ O ( n ǫ ) with approximation factor O ((1 /ǫ ) O (1 /ǫ ) ) for any ǫ > Theorem 9.
For any constant ǫ > , there exists an algorithm for dynamic LIS whose worst-caseupdate time is ˜ O ( n ǫ ) and whose approximation factor is O ((1 /ǫ ) O (1 /ǫ ) ) . Dynamic worst-case approximationalgorithm update time factor A ′ ˜ O ( n ) 1 A ′ ˜ O ( n / κ ) O (1 /κ ) A ′ ˜ O ( n / κ ) O (1 /κ ) A ′ ˜ O ( n / κ ) O (1 /κ )... ... ... A ′ k ˜ O ( n k +2 + κ ) O (1 /κ ) k Table 2: Guarantees of the dynamic solutions are shown in this figure.block-based m f ( n ) g ( n ) h ( n ) approximationalgorithm factor A n / ˜ O ( n κ ) n / ˜ O ( n / κ ) O (1 /κ ) A n / ˜ O ( n κ ) n / ˜ O ( n / κ ) O (1 /κ ) A n / ˜ O ( n κ ) n / ˜ O ( n / κ ) O (1 /κ )... ... ... ... ... ... A k n k +2 ˜ O ( n κ ) n k +1 k +2 ˜ O ( n k +2 + κ ) O (1 /κ ) k Table 3: Guarantees of the block-based solutions are shown in this figure. We assume that thelength of the initial array a for the block-based algorithm is n . Proof.
The proof is by induction. Let us fix a constant 0 < κ < k ≥
1, our aim is to design a dynamic algorithm for
LIS with approximation factor O ((1 /κ ) k )24nd worst-case update time ˜ O ( n k +2 + κ ). We call such an algorithm A ′ k . The base case is for k = 0for which we already know a solution A ′ . We also strengthen our hypothesis: If instead of startingfrom an empty array, we start with an array of length n , our algorithm needs a preprocessing timeof ˜ O ( n κ ).Let us assume that for k ≥ A ′ k − with desirable guarantees is available and the goal is todesign A ′ k . To this end, we first make a block-based algorithm A k with the following properties:For an initial array a of length n , we set f ( n ) = n κ , g ( n ) = n k +1 k +2 , and h ( n ) = ˜ O ( n k +1 k +2 + κ ). Similarto what we did in Lemma 7, we map every element of the initial array a onto the 2D plane byputting a point ( i, a i ) for every element. We set m = n k +2 and divide the plane into an m × m grid,such that in each row and in each column there are at most ⌈ n/m ⌉ points. Moreover, we constructa grid packing solution for the m × m grid with approximation guarantee ( ˜ O ( m κ ) , O (1 /κ )). Next,for each segment we initiate an LIS instance that will be solved with algorithm A ′ k − .The preprocessing time consists of two parts: (i) constructing the solution to grid packing intime ˜ O ( m κ ) and (ii) constructing an initial solution for each segment. Since the problem size foreach segment is bounded by n/m and every element appears in at most ˜ O ( m κ ) segments and theinitialization time for A ′ k − is ˜ O ( n κ ) this can be bounded by ˜ O ( m κ n ( n/m ) κ ) = ˜ O ( n κ ). Thus,the total preprocessing time is bounded by˜ O ( m κ + n κ ) = ˜ O ( n κ ) . By the construction of the grid, the size of the problem for each segment is bounded by O ( n/m ) = O ( n k +1 k +2 ). Also, since g ( n ) = O ( n k +1 k +2 ), the size of the problem instance correspond-ing to each segment remains in this range throughout the g ( n ) many steps. Each time an operationarrives, we update the solution for ˜ O ( m κ ) many segments each in time ˜ O (( n/m ) k +1 + κ ) (recall thatwe use A ′ k − for the solution of the segments). Thus, the update time is bounded by˜ O ( m κ ( n/m ) k +1 + κ ) = ˜ O ( n κ ( n/m ) k +1 )= ˜ O ( n κ ( n k +1 k +2 ) k +1 )= ˜ O ( n κ n k +2 )= ˜ O ( n k +2 + κ ) . Moreover, in order to find an approximate solution for
LIS using non-conflicting segments, we needto run a DP in time ˜ O ( m κ ) = ˜ O ( n κk +2 ) = ˜ O ( n k +2 + κ ). Thus, the overall worst-case update timeis equal to h ( n ) = ˜ O ( n k +2 + κ ).Finally, the approximation factor increases by a multiplicative factor of O (1 /κ ) in each levelof recursion. Thus, the approximation factor of A k is bounded by O ((1 /κ ) k ). Using Lemma 2,we can the turn block-based algorithm A k into an algorithm for LIS with worst-case update time˜ O ( n k +2 + κ ). Finally, since we are constructing A ′ k from a block-based algorithm with preprocessingtime ˜ O ( n κ ), if we start from an array a of length n , we need a preprocessing time of ˜ O ( n κ )which is another condition of the hypothesis.Now, for a fixed ǫ >
0, we set κ = ǫ/ k = ⌈ /ǫ ⌉ . Thus, the worst-case update time of the25lgorithm would be bounded by ˜ O ( n k +2 + κ ) ≤ ˜ O ( n k + κ )= ˜ O ( n k + ǫ/ ) ≤ ˜ O ( n ǫ/ ǫ/ )= ˜ O ( n ǫ )which is desired. Also, the approximation factor would be bounded by O ((1 /ǫ ) O (1 /ǫ ) ).26 ǫ Approximation for
DTM
In this section, we give a dynamic algorithm for
DTM with approximation factor 1 + ǫ and updatetime O (log n ). If access to the elements of the array is provided in time O (1), the update timeimproves to O (log n ). However, since we use a balanced binary tree for the elements, there is anadditional O (log n ) overhead for the update time. We explain the algorithm in four steps. In thefirst step, we present a simple algorithm that obtains an approximation factor of 2 with the sameupdate time. Next, in Step 2, we show how a 2-approximate solution can be used to obtain an exactsolution in time O ( k log n ) when the solution size is bounded by k . In the third step, we improvethe runtime of the same algorithm to O ( k log n ). Finally, we show in the last step that such analgorithm along with the 2-approximate solution in time O (log n ) gives us a 1 + ǫ approximatesolution with update time O (log n ). -approximate Solution for DTM
Similar to previous work [17], we call a pair ( a i , a j ) an inversion , if i < j but a i > a j . The heartof the analysis is that a maximal set of disjoint inversion pairs is a 2-approximate solution for DTM . We first formally give a proof to this claim and next show how such a maximal set can bemaintained with O (log n ) update time. Observation 1.
Let a = h a , a , . . . , a n i be an array of length n and S = { ( a α , a β ) , ( a α , a β ) , . . . } be a maximal set of disjoint inversions of a . Then we have | S | ≤ DTM ( a ) ≤ | S | . Proof.
Since every pair ( a α i , a β i ) is an inversion, then any solution for DTM should remove oneelement from each pair which implies
DTM ( a ) ≥ | S | . On the other hand, if we remove all the 2 | S | elements of S from a , the remaining subsequence is increasing since S is maximal and thereby thereis no inversion in the remaining elements. This implies that DTM ( a ) ≤ | S | .Based on Observation 1, our 2-approximate algorithm maintains a maximal set of disjointinversions with update time O (log n ). Lemma 10.
There exists a -approximate solution for DTM with update time O (log n ) .Proof. Our algorithm maintains a maximal collection of disjoint inversion pairs, namely S . Inaddition to this, both the elements used in this collection and the elements not used in this collectionare stored in a balanced tree that allows for search, insertion, and deletion in logarithmic time.We refer to the tree containing the elements of S with T S and the tree containing other elementsby T N .Whenever a new element a i is inserted into the array, we first check if it makes an inversionwith the elements of T N . Notice that these elements are increasing in the order of their indicessince there is no inversion between them. Thus, in order to verify whether a i makes an inversionwith any element of T N , we just need to compare that to the largest a j ∈ T N which is smallerthan a i or the smallest a j ∈ T N which is larger than a i . Both of these two operations can be donein time O (log n ) (the exponent of log is 2 since it takes time O (log n ) for us to get the value of Red black tree could be one implementation. i ’th element of the array). If an inversion is detected, we add it to S and update T N and T S accordingly. Otherwise, we add a i into T N .Removing an element is also strait-forward. If the element belongs to T N , then no action isrequired other than updating T N . Otherwise, after removing a i , we have to be careful about theelement which made an inversion with a i previously. That can be handled in time O (log n ) similarto adding new elements. We check if it makes an inversion with the elements of T N and updateboth T N and T S accordingly. All these operations can be done in time O (log n ). -approximate Solution to an Exact Solution We show that a 2-approximate solution for
DTM can be used to obtain an exact solution. In fact,this idea carries over to any constant approximate solution but for simplicity we state it only for2-approximate solutions. Let us denote the size of the 2-approximate solution by k . This way, weknow that the optimal solution is in range [ k/ , k ].We first construct a graph G in the following way. Every element of the array becomes onevertex of G and we put an edge between two vertices if their corresponding elements in a make aninversion. This way, finding distance to monotonicity of array a is equivalent to finding the smallestvertex cover of G .Let set S be all the elements that are removed from the array in our 2-approximate solution(thus we have | S | = k ). We refer to the vertices of G corresponding to set S by v , v , . . . , v k .The key observation is that every edge of the graph is incident to at least one vertex v i otherwise ∪ i ∈ [ k ] { v i } would not be a valid vertex cover.We call a vertex of the graph low-degree if its degree is upper bounded by k and high-degree otherwise. Based on this, we divide the vertices corresponding to set S into two disjoint sets L and H containing the low-degree and high-degree vertices. All vertices of H have to be included in theoptimal solution otherwise all their neighbors should be included and their number is more than k .Thus, we can include those vertices in our solution and remove them from the graph (this includestheir incident edges too).For each remaining edge of the graph, one end point is in L . Moreover, the degrees of thevertices in L are bounded by k . Thus, the total number of remaining edges in the graph is boundedby k . Therefore, apart from at most 2 k vertices, all the other vertices are isolated and definitelydo not contribute to the vertex cover. Thus, we need to solve the problem for O ( k ) many elements.This is equivalent to finding DTM for O ( k ) many vertices which can be solved in time O ( k log n ).There is an additional O (log n ) overhead involved if access to each element requires time O (log n ). Lemma 11.
Let a be an array of length n and S be a set of k elements whose removal from a makes a increasing. Provided oracle access to the elements of a , one can compute the distance tomonotonicity of a in time O ( k log n ) .Proof. The correctness of the algorithm is already discussed. Here we just show a bound on theruntime. Since set S is given, we just need to compute the degree of each vertex. There are k elements in set S so detecting the edges between them can be done in time O ( k ). Moreover, forevery vertex v i corresponding to the elements of S , detecting its edges to the rest of the elementscan also be done in time O (log n ) since a binary search suffices for that purpose. Therefore, thetotal runtime is O ( k log n ). 28 .3 Exact Solution in Quasi-linear Time We show that the runtime of the algorithm of Section 6.2 can be improved to quasi-linear. Letus for simplicity divide the element of the array into two sets S and N . Set S corresponds tothe elements of the approximate solution (whose removal makes the array increasing) and set N contains the rest of the elements. Obviously, set N is increasing otherwise S would not be a validsolution to distance to monotonicity. The key to our improvement is the following observation: Observation 2.
Let a i < a j < a k be three elements of set N and a l be an element of set S . If both ( a i , a l ) and ( a k , a l ) are inversions, then ( a j , a l ) is also an inversion.Proof. Notice that since we have a i < a j < a k and all three are in N , then we can infer that i < j < k . On the other hand, since both ( a i , a l ) and ( a k , a l ) are inversions, then either both l < i and a l > a k hold or both l > k and a l < a i hold. In either case, ( a j , a l ) makes an inversion.Observation 2 shows that any element of S makes an inversion with an interval of the elementsin N . This implies an important consequence: Label each element a i ∈ N with a set of elements I ( a i ) ⊆ S such that for each element a j ∈ I ( a i ), pair ( a i , a j ) makes an inversion. Based onObservation 2 we can prove that the total number of distinct labels in N is bounded by 2 | S | + 1. Lemma 12.
For each element a i ∈ N , define its label by I ( a i ) ⊆ S where I ( a i ) contains allelements of S that make an inversion with a i . Then we have: | [ a i ∈ N { I ( a i ) }| ≤ | S | + 1 . Proof.
For each element a j ∈ S that makes an inversion with an element of N define two thresholds α and β where α is the smallest element of N that makes an inversion with a j and β is the smallestelement of N larger than α that does not make an inversion with a j . Due to Observation 2, anelement of N makes an inversion with a j if and only if its value is at least α and smaller than β .The total number of thresholds for all elements of S is at most 2 | S | . Moreover if two elements of N are not separated by any threshold, then their labels are the same. Thus, the total number ofdistinct labels is bounded by 2 | S | + 1.Lemma 12 is important from an algorithmic point of view because of the following: if twoelements have the same label (and thus the same set of conflicting elements in S ), either they bothcontribute to the optimal solution (removed from the array) or they both remain in the array.Thus, one can merge these elements and make a larger element in the array that represents bothof them. More generally, for each label, if we merge all the element attributed to that label andmake a single element out of them (with a larger size), the size of the optimal solution remainsunchanged. Since the total number of labels is bounded by 2 | S | + 1 then this transformation leavesus with 2 | S | + 1 elements and we only need to solve the problem for them. This can be done intime O ( k log n ) as shown in Lemma 13. We note that in the above, we assume random access tothe elements of the array is provided in time O (1). Lemma 13.
Given query access to an array a of length n and a -approximate solution for distanceto monotonicity of a with size k , one can find an exact solution for distance to monotonicity intime O ( k log n ) . S Figure 16: Inversions between the elements of S and L are shown in this figure. Elements of N with equal labels are colored similarly. Proof.
The algorithm and its correctness is outlined above. Here we just explain the runtime. Sincethe elements of N are stored in a balanced tree data structure, for each element of S we can findin time O (log n ) which interval of the elements of N makes an inversion with it. This takes a totalruntime O ( k log n ). Next, we sort all the intervals based on them and merge elements of N whoselabels are the same. We refer to these merged elements as super elements. The value of a superelement can be equal to the value of an arbitrary element which is used in its construction.After constructing the super elements in time O ( k log n ) the size of the problem reduces to O ( k ). However, patience sorting does not solve this problem since super elements have weights. Inother words, removing a super element incurs a cost equal to the number of elements used to makeit. Nonetheless, it is known [21] that even if the elements are weighted, for an array of size k , onecan solve both LIS and
DTM in time O ( k log k ). ǫ Approximation for
DTM with Update Time O (log n ) The last step is to obtain a 1 + ǫ approximate solution using the above techniques. In parallel, wealways run the algorithm of Section 6.1 to maintain a 2-approximate solution. In order to obtaina 1 + ǫ approximation algorithm, we use the framework of Section 3. To design our block-basedalgorithm we start with an array of length n . We set the preprocessing time to O ( k log n ) where k is the size of the 2-approximate solution (this we know by the parallel algorithm that we run).In the preprocessing phase, we find an exact solution (say k ′ ≥ k/
2) in time O ( k log n ) for thearray and report it as the value of distance to monotonicity. We set g ( a ) = ǫk/ ǫk/ d + i for the i ’th operation where d is the solution for the initial array. This The additional O (log n ) factor is due to the data structure used for random access to the elements of the array.
30s clearly an upper bound on the size of the solution as well as a 1 + ǫ approximation of it. Thus,the worst-case update time is O (1).By Lemma 3, our block-based algorithm can be turned into a dynamic algorithm with worst-caseupdate time O (log n ). Theorem 14.
For any ǫ > , there exists a dynamic algorithm for distance to monotonicity withapproximation factor ǫ and worst-case update time O (log n ) .Proof. For an array a , our block-based algorithm has preprocessing time f ( a ) = O ( k log n ) where k = DTM ( a ). Also, g ( a ) = ǫk/ h ( a ) = O (1). Thus, by Lemma 2, the worst-case update timeof the equivalent dynamic algorithm is O (log n ). Notice that since after g ( a ) steps the size of the DTM ( a ) changes by a small factor, all functions f, g, and h remain asymptotically the same whichimplies relativity. 31 eferences [1] N. Ailon, B. Chazelle, S. Comandur, and D. Liu. Estimating the distance to a monotonefunction. In RANDOM 2004 .[2] A. Andoni and H. L. Nguyen. Near-optimal sublinear time algorithms for ulam distance. In
SODA 2010 .[3] S. Assadi, K. Onak, B. Schieber, and S. Solomon. Fully dynamic maximal independent setwith sublinear in n update time. In
SODA 2019 .[4] S. Assadi, K. Onak, B. Schieber, and S. Solomon. Fully dynamic maximal independent setwith sublinear update time. In
STOC 2018 .[5] S. Behnezhad, M. Derakhshan, M. Hajiaghayi, C. Stein, and M. Sudan. Fully dynamic maximalindependent set with polylogarithmic update time. In
FOCS 2019 .[6] M. Boroujeni and S. Seddighin. Improved MPC algorithms for edit distance and ulam distance.In
SPAA 2019 .[7] A. Chen, T. Chu, and N. Pinsker. The dynamic longest increasing subsequence problem. arXivpreprint arXiv:1309.7724 , 2013.[8] G. Cormode, M. Mitzenmacher, and J. Thaler. Streaming graph computations with a helpfuladvisor. In
ESA 2010 .[9] S. Dasgupta, C. H. Papadimitriou, and U. V. Vazirani.
Algorithms . McGraw-Hill HigherEducation, 2008.[10] Y. Dodis, O. Goldreich, E. Lehman, S. Raskhodnikova, D. Ron, and A. Samorodnitsky. Im-proved testing algorithms for monotonicity. In
RANDOM-APPROX 1999 .[11] F. Erg¨un, S. Kannan, R. Kumar, R. Rubinfeld, and M. Viswanathan. Spot-checkers. In
STOC1998 .[12] E. Fischer. The art of uninformed decisions.
Bulletin of the EATCS , 75:97, 2001.[13] M. L. Fredman. On computing the length of longest increasing subsequences.
Discrete Math-ematics , 11(1):29–35, 1975.[14] A. G´al and P. Gopalan. Lower bounds on streaming algorithms for approximating the lengthof the longest increasing subsequence. In
FOCS 2007 .[15] P. Gawrychowski and W. Janczewski. Fully dynamic approximation of lis in polylogarithmictime, 2020.[16] P. Gawrychowski, A. Karczmarz, T. Kociumaka, J. Lacki, and P. Sankowski. Optimal dynamicstrings. In
SODA 2018 .[17] P. Gopalan, T. S. Jayram, R. Krauthgamer, and R. Kumar. Estimating the sortedness of adata stream. In
SODA 2007 . 3218] A. Grønlund and S. Pettie. Threesomes, degenerates, and love triangles. In
FOCS , 2014.[19] M. Henzinger, S. Krinninger, D. Nanongkai, and T. Saranurak. Unifying and strengtheninghardness for dynamic problems via the online matrix-vector multiplication conjecture. In
STOC 2015 .[20] S. Im, B. Moseley, and X. Sun. Efficient massively parallel methods for dynamic programming.In
STOC 2017 .[21] G. Jacobson and K.-P. Vo. Heaviest increasing/common subsequence problems. In
AnnualSymposium on Combinatorial Pattern Matching , pages 52–66. Springer, 1992.[22] T. Kociumaka and S. Seddighin. Improved dynamic algorithms for longest increasing subse-quence, 2020.[23] J. Lacki, J. Ocwieja, M. Pilipczuk, P. Sankowski, and A. Zych. The power of dynamic distanceoracles: Efficient dynamic algorithms for the steiner tree. In
STOC 2015 .[24] M. Mitzenmacher and S. Seddighin. Dynamic algorithms for
LIS and distance to monotonicity.In
STOC , 2020.[25] M. Mitzenmacher and S. Seddighin. Erd \ ” { o } s-szekeres partitioning problem. arXiv preprintarXiv:2011.10870 , 2020.[26] M. Mitzenmacher and S. Seddighin. Improved sublinear time algorithms for longest increasingsubsequence. In SODA , 2021.[27] D. Nanongkai and T. Saranurak. Dynamic spanning forest with worst-case update time: adap-tive, las vegas, and o(n1/2 - ǫ )-time. In STOC 2017 .[28] D. Nanongkai, T. Saranurak, and C. Wulff-Nilsen. Dynamic minimum spanning forest withsubpolynomial worst-case update time. In
FOCS 2017 .[29] T. Naumovitz, M. E. Saks, and C. Seshadhri. Accurate and nearly optimal sublinear approx-imations to ulam distance. In
SODA 2017 .[30] S. Pettie.
On the shortest path and minimum spanning tree problems . PhD thesis, 2003.[31] P. Ramanan. Tight ω (n lg n) lower bound for finding a longest increasing subsequence. International journal of computer mathematics , 65(3-4):161–164, 1997.[32] A. Runbinstein, S. Seddighin, Z. Song, and X. Sun. Approximation algorithms for LCS andLIS with truly improved running times. In
FOCS , 2019.[33] M. Saks and C. Seshadhri. Estimating the longest increasing sequence in polylogarithmic time.In
FOCS , 2010.[34] R. B. Yehuda and S. Fogel. Partitioning a sequence into few monotone subsequences.
ActaInformatica , 35(5):421–440, 1998. 33
Streaming Algorithm for
LIS
We outlined an improved streaming algorithm for
LIS in Section 2. Here we give a proof for itscorrectness and a bound on its memory. In this setting, we assume that the input is available tous in any desired order. We call this setting, streaming with advisory help. Previous work solvesthe problem with memory O ( √ n ) within a factor 1 + ǫ in a single round [17]. Observation 3.
For any < κ < , there exists a streaming algorithm that uses advisory helpand approximates the LIS of an array of length n with memory ˜ O ( n / κ ) within a factor O (1 /κ ) in three rounds. This algorithm is randomized and gives an approximate solution with probabilityat least − /n .Proof. Let m = n / be the size of the grid. We use an ( O ( m κ log m ) , O (1 /κ )) approximate solutionof grid packing to cover the grid cells with segments. Similar to what we did before, we think ofeach element i of the array as a point ( i, a i ) of the 2D plane. As mentioned earlier, in the firstround, we sample m − n/m log n with probability at least 1 − /n . Also, we draw the vertical lines evenly so that they divide theelements into chunks of size n/m .In the next two rounds, we ask for the elements of the array in the row-order and column-order.More precisely, in the second round, we first ask for the elements falling in the first row of the grid(in the column order). Next, we ask for the elements of the second row and so on. For each row,we approximate the value of the LIS for each segment. Since the total number of elements in everyrow is bounded by 10 n/m log n , we only need memory ˜ O ( p n/m log n ) = ˜ O ( n / ) to approximatethe value of LIS for each segment. However, we need this much memory for multiple segments.This adds an overhead of ˜ O ( m κ ) to the memory since each grid cell may be covered by at most˜ O ( m κ ) segments. Similarly, in the third round, we ask for the elements in the column-order.Finally, we use a DP to find a subset of non-conflicting segments with the largest total sum of LIS . This can be done with memory ˜ O ( m κ ) = ˜ O ( n / κ ) as the number of segments is boundedby ˜ O ( m κ ).The correctness of the algorithm is similar to the one given for dynamic LIS . We fix an arbitrary
LIS of the array and assume that the adversary puts the contribution of each cell of the grid to thefixed
LIS . The
LIS of each segment is a clear upper bound on the score of that segment on the grid,however, if we use those values instead of their scores, we still obtain a valid solution. Finally, sinceour solution for the grid packing problem is ( O ( m κ log m ) , O (1 /κ )) approximate, then the score weobtain using non-conflicting segments is at least an Ω( κ ) fraction of the score of the grid which isequal to the size of the LIS . 34
Improved Algorithm for
LIS + We provide the intuition behind the algorithm and then the formal proof. For simplicity, we assumehere that we have random access to all elements of the array in time O (1). Our first goal is todesign a block-based algorithm for an array a of length n . We set f ( n ) = O ( n log n ) and in thepreprocessing phase we compute the LIS of a . Let this value be x . Since we only add elements inthe LIS + problem, from here on, x is a lower bound for the solution value. For the next g ( n ) = √ n operations, every new element is added to a separate set, and after each operation, the LIS of theseparate set is computed in time O ( √ n log n ). At an arbitrary step, let this value be y . The keyobservation is that the overall LIS of the array is in range [max { x, y } , x + y ] ≤ { x, y } . Wetherefore have a 2-approximate solution by just reporting max { x, y } . This block-based algorithmfor LIS + with f ( n ) = O ( n log n ), g ( n ) = √ n , and h ( n ) = O ( √ n log n ) yields a dynamic algorithmwith worst-case update time ˜ O ( √ n ).We recurse to improve the runtime down to O ( n ǫ ) for any ǫ >
0. Instead of using the naivealgorithm for the g ( n ) operations after the initialization, we can use the more advanced algorithmexplained above (its update time is ˜Ω( √ n ) better than computing the LIS from the scratch everytime). Similar to what we did in 5, in each level of recursion, we use the previous algorithm for theoperations after initialization. The advantage of this approach in this setting over Section 5 is thatthe approximation factor of the algorithm depends linearly on 1 /ǫ (and not exponentially). To seethis, assume that at some point, x is the solution for the initial array and y is an α -approximationfor the solution of the second set of operations. The optimal solution is upper bounded by x + αy and lower bounded by max { x, y } . Therefore, by reporting max { x, y } we can be sure that ourapproximation factor is bounded by α + 1. In other words, if we recurse on this algorithm α times,then the approximation factor is bounded by α + 1. This results in an algorithm with worst-caseupdate time ˜ O ( n ǫ ) and approximation factor O (1 /ǫ ). Observation 4.
For any constant ǫ > , there exists an algorithm for dynamic LIS + whose worst-case update time is ˜ O ( n ǫ ) and whose approximation factor is O (1 /ǫ ) . If one could show the statement of Observation 4 for any (possibly sub-constant) ǫ >
0, thenby setting ǫ = 1 / log n , we could obtain a dynamic algorithm for LIS + with polylogarithmic updatetime and logarithmic approximation factor. However, since there is a constant factor overheadin every recursion, Observation 4 only works when ǫ is constant. This overhead is incurred inthe reduction from dynamic algorithms to block-based algorithms. In the following, we providea variation of the same algorithm that does not use this reduction and achieves polylogarithmicupdate with and logarithmic approximation. Theorem 15.
There exists an algorithm for dynamic
LIS + whose worst-case update time is O (log n ) and whose approximation factor is O (log n ) .Proof. In our algorithm, we put the elements in buckets and for every bucket, we compute thevalue of the
LIS . As more buckets are made, we combine them to construct larger buckets. Thesizes of the buckets are always powers of 2.In the beginning, the array is empty and there are no buckets. When the first element isinserted, we construct the first bucket that contains only that element. After the construction ofeach bucket, we compute the
LIS of that bucket over the next steps. More precisely, when a bucketof size k is constructed, we divide the task of computing the LIS of that bucket into k pieces and351 212 312 3 412 34 5 12 34 5 612 34 56 712 34 856 712 34 56 78 912 34 56 78 9 101 :2 :3 :4 :5 : 6 :7 :8 :9 :10 :Figure 17: The buckets are shown for the first 10 operations. Buckets that are disconnected andare held together with dashed rectangles are not finalized yet. Connected pieces show finalizedbuckets.execute these pieces in the next k operations. Thus, when a bucket of size 1 is constructed, its LIS iscomputed immediately. We say a bucket is finalized , when our algorithm has already computed its
LIS . In our algorithm, we only merge finalized buckets to make larger ones and thus, we maintainthe property that at each point in time, each element appears in exactly one finalized bucket.Every time a new element is inserted, we make a bucket containing that element alone. However,when there are two finalized buckets of the same size (say k ), we merge them to obtain a bucket ofsize 2 k . After this, it takes 2 k − LIS of the array by the maximum solution for anyof the finalized buckets. We prove that with this construction, there are at most O (log n ) finalizedbuckets at every point in time and moreover, the number of buckets that are not finalized is alsobounded by O (log n ).This immediately implies that the approximation factor of our algorithm is bounded by O (log n ).The reason is that each element is always included in exactly one finalized bucket at a time andtherefore the total sum of LIS ’s for all finalized buckets is an upper bound on the size of the solution.Moreover, the maximum solution size for each bucket is a lower bound on the
LIS of the entire array.Since the number of finalized buckets is bounded by O (log n ) this implies that the approximationfactor of our algorithm is bounded by O (log n ).We also bound the runtime by O (log n ). In our algorithm, at every point in time, there are O (log n ) different buckets that are not finalized yet. The total runtime needed to compute the LIS of a bucket of size k is O ( k log k ) which is divided over k steps. Thus, each bucket which is notfinalized yet requires time at most O (log n ) for each step. Thus the overall runtime is O (log n ) foreach step. One thing to keep in mind is that we use a balanced tree data structure to access theelements of the array which adds an overhead of O (log n ). Therefore, the worst-case update timeis O (log n ).It follows from the construction of the buckets that at each step, there is at most one bucketof each size which is not finalized. The reason is that after a bucket of size k is made, it takes k more steps to make another bucket of the same size. However, before the new bucket is made, thefirst one will be finalized. Since the sizes of the buckets are powers of 2, this implies that there aremost ⌊ log n ⌋ such buckets. Moreover, this also shows that the number of finalized buckets of eachsize is bounded by 3, otherwise this makes two buckets of larger size that are not finalized yet.37 Sequential Algorithm for
DTM
We present a simple comparison-based algorithm for
DTM with approximation factor 2 that runsin time O ( n ). Using Lemma 12, the approximation factor improves to 1 + ǫ in the following way:If the solution size is bounded by √ n , then Lemma 12 gives an exact solution in time ˜ O ( √ n ).Otherwise, one can find a 1 + ǫ approximate solution in time ˜ O ( √ n ) using the solution of [29].Thus, the main bottleneck of the runtime is for the computation of an approximate solution, whichwe show can be done in time O ( n ).By Observation 1, a 2-approximate solution can be obtained by computing a maximal set ofinversion pairs. Our algorithm finds such a set in linear time.We begin by a empty stack. We iterate over the elements of the array and each time we comparethe new element to the element at the top of the stack (if any). If this pair makes an inversion,we put this pair in a set S and remove the last element of the stack. Otherwise, we put the newelement on top of the stack and continue on. Obviously, the runtime is O ( n ), since each element a i is processed in time O (1). The correctness of the algorithm follows from the fact that the numbersof the stack are always increasing and therefore there is no inversion between them. Thus, set S isa maximal set of inversion pairs. Observation 5.
For any constant ǫ > , DTM can be approximated within a factor ǫ in time O ( n ) . We remark that in the above observation, factors that depend on 1 /ǫ are hidden in the O notation. 38 The Algorithm of Chen et al. [7]
For formal proofs, we refer the reader to [7]. Chen et al. [7] propose the following algorithm tomaintain a solution for dynamic
LIS .For each element i of the array, define l ( i ) to be the size of the longest increasing subsequenceending at element a i of the array. Chen et al. [7] refer to this quantity as the level of element i . Notice that l ( i ) can be computed in time ˜ O ( n ) for all elements of the array using the patiencesorting algorithm.Define L k to be the set of elements whose levels are equal to k . The algorithm of Chen et al. [7]maintains a balanced binary tree for each L k that contains the corresponding elements. One keyobservation is that for each k , all the elements of L k are decreasing, otherwise their levels wouldnot be the same.When a new element is added to the array, L k ’s may change. More precisely, after an elementaddition, the levels of some elements may change (but only by 1). Similarly, element removal maychange the levels of the elements of the array but again the change is bounded by 1. Chen etal. [7], show that after an insertion, for each L k , the levels of only one interval of the elements mayincrease. In other words, for each L k , there are two numbers α and β such that all the elementswhose values are within [ α, β ] increase their levels and the rest remain in L k .Thus, they use a special balanced tree structure that allows for interval deletion and intervaladdition in logarithmic time. Therefore, all that remains is to detect which interval of each L k changes after each operation. They show that this can be computed in time O (log n ) for all L k ’svia binary search. Since the number of different levels is equal to the size of the LIS , their updatetime depends on the size of the solution. L = h i L = h , i L = h ih , , , , , , , , , ih , , , , , , , , i L = h i L = h i L = h , i L = h i n elements are given, their runtime for constructing the data structure is ˜ O ( n ) sincepatience sorting gives us all the levels in time ˜ O ( n ) and the balanced trees can be constructed intime ˜ O ( n ) for all L kk