RLE edit distance in near optimal time
Rapha\"el Clifford, Pawe{\l} Gawrychowski, Tomasz Kociumaka, Daniel P., Martin, Przemys{\l}aw Uzna\'nski

TL;DR
This paper presents a near-optimal algorithm for computing edit distance between run-length encoded strings, significantly improving previous results and approaching theoretical limits under standard complexity assumptions.
Contribution
The authors develop an algorithm that computes run-length encoded edit distance in near-optimal time, closing a research gap since 1993.
Findings
Achieves $ ilde{O}(mn)$ time complexity for run-length encoded strings.
Improves previous algorithms by a factor of $ ilde{n}/ ext{log}(mn)$.
Time complexity is near optimal under SETH-hardness.
Abstract
We show that the edit distance between two run-length encoded strings of compressed lengths and respectively, can be computed in time. This improves the previous record by a factor of . The running time of our algorithm is within subpolynomial factors of being optimal, subject to the standard SETH-hardness assumption. This effectively closes a line of algorithmic research first started in 1993.
| Type DI | Type ID | Type IF | Type FD | Type FI | Type DF |
| Type -I | Type -F | Type -D | Type I- | Type F- | Type D- |
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
RLE edit distance in near optimal time
Raphaël Clifford
Department of Computer Science, University of Bristol, UK
Paweł Gawrychowski
Institute of Computer Science, University of Wrocław, Poland
Tomasz Kociumaka Supported by ISF grants no. 824/17 and 1278/16 and by an ERC grant MPM under the EU’s Horizon 2020 Research and Innovation Programme (grant no. 683064). Department of Computer Science, Bar-Ilan University, Israel
Institute of Informatics, University of Warsaw, Poland
Daniel P. Martin
School of Mathematics, University of Bristol, UK
Heilbronn Institute for Mathematical Research, Bristol, UK
Przemysław Uznański
Institute of Computer Science, University of Wrocław, Poland
Abstract
We show that the edit distance between two run-length encoded strings of compressed lengths and respectively, can be computed in time. This improves the previous record by a factor of . The running time of our algorithm is within subpolynomial factors of being optimal, subject to the standard SETH-hardness assumption. This effectively closes a line of algorithmic research first started in 1993.
1 Introduction
The edit distance is one of the most common distance measures between strings. For two strings of length and respectively, the edit distance counts the minimum number of single character insertions, deletions and substitutions needed to transform one string into the other. The first record of an algorithm to compute the edit distance is from 1968 [14] although it was rediscovered independently a number of times subsequently. Masek and Paterson improved the running time to in 1980 and this is the fastest known algorithm to date [12]. Much more recently it has been shown no time edit distance algorithm can exist, subject to the strong exponential time hypothesis (SETH) [4, 5]. As a result, it is likely that little further progress can be made in terms of improving its worst case complexity.
In this paper we focus on the problem of computing the edit distance between two compressed strings. The run-length encoding (RLE) of a string compresses consecutive identical symbols into a run, denoted if the symbol is repeated times. For example aaabbbbaaa would be compressed to . This form of compression is commonly used for image compression but also has wider applications including, for example, in image processing [9, 15] and succinct data structures [11].
In 1993 Bunke and Csirik proposed the first algorithm for computing the edit distance between RLE strings. For two strings of RLE-compressed lengths and respectively, their algorithm runs in time in the special case where all the runs are of the same length [6]. However the running time falls back to the naive complexity of time in the worst case where and are the uncompressed lengths of the two strings. This worst case complexity was subsequently improved to [7, 3] and then time in 2007 [10]. Finally in 2013 the fastest solution prior to this current work was given running in time, where [8]. This was the also the first algorithm for the RLE edit distance problem whose running time did not depend on the uncompressed lengths of the input strings.
For uncompressed strings, the longest common subsequence (LCS) problem has long been considered a close relative of the edit distance problem. This is partly due to the similarity of their dynamic programming solutions and partly because LCS is a special case of edit distance when general costs are allowed for the different mismatch and substitution operations. Moreover, the two problems have the same quadratic time upper bounds and SETH-hardness lower bounds [5]. Somewhat surprisingly, however, the history of algorithms for LCS and edit distance have not mirrored each other when the problems are considered on RLE strings. In particular, an time algorithm for computing the LCS on RLE strings was given in 1999 [2] which is considerably faster than has been possible up to this point for the edit distance problem. Some work has also been carried out since that date to improve the log factor in the running time complexity for the LCS problem [1, 13].
In this paper we speed up the running time for the edit distance problem on RLE strings by a factor of , matching the fastest LCS algorithm to within a logarithmic factor and making it within subpolynomial factors of being optimal, assuming SETH holds. As a result, our new algorithm shows that the LCS and edit distance problems are indeed of essentially the same complexity even when the input strings are run-length encoded. This effectively closes a line of algorithmic research first started in 1993.
Theorem 1.1**.**
Given two RLE strings of compressed length and respectively, there exists an algorithm to compute their edit distance which runs in time.
2 Previous Work and Preliminaries
The classic dynamic programming solution for computing the edit distance between uncompressed strings and of uncompressed lengths and respectively, computes the distance between all prefixes and . The key recurrence which enables us to do this efficiently is given by:
[TABLE]
From this the classic time solution follows directly.
The previous approaches for the edit distance problem on RLE strings take this recurrence and the implied dynamic programming table as their starting point. The basic idea was introduced by Bunke and Csirk [6] whose algorithm works by dividing the dynamic programming table into “blocks”, where each block is defined by a run in the original strings.
For each block the central task is to compute its bottom row and rightmost column given the bottom row of the block above and the rightmost column of the block to the left. For simplicity of terminology, we will refer to the rightmost column of the block to the left and the bottom row of the block above collectively as the input border of a block and the bottom row and rightmost column of a block as its output border. Figure 1 illustrates an example.
In [7, 3] it was shown that the work needed to derive the values of all the output borders of blocks is at most linear in their length. When computing the edit distance between strings and , the length of each row in the dynamic programming table is the uncompressed length of string and the length of each column is the uncompressed length of . If there are runs in string and runs in then the total time complexity for computing the edit distance using their approach is therefore .
The work closest to ours is the algorithm of Chen and Chao [8]. They observe that the borders of the blocks in the dynamic programming table are piecewise linear with gradient or [math]. The borders can be therefore concisely represented by specifying their starting values as well as the positions and types of the points of changing gradient called the turning points. They prove that for a given block the number of turning points in an output border is at most a constant greater than in its input border. Consequently, a simple calculation shows that the total number of turning points is (for ). Chen and Chao arrive at their final complexity by designing a procedure that computes the representation of the output border of a block, given the representation of its input border, in time proportional to the number of turning points. We now summarise their approach using our own notation.
There are two distinct types of blocks in the dynamic programming table. A match block corresponds to a rectangle where the corresponding symbols in the two strings match. A mismatch block corresponds to a rectangle where the corresponding symbols mismatch. Figure 1 shows both match and mismatch blocks. Borrowing notation from [8] we say that element of the dynamic programming table ED is in diagonal . Let be the intersection of the input border with diagonal .
Lemma 2.1** ([8, Lemma 1]).**
For a match block, .
Lemma 2.1 indicates that for a match block we can simply copy the values from the corresponding position in the input border to derive the values of the output border. The main challenge is therefore how to handle mismatch blocks.
For mismatch blocks Chen and Chao’s algorithm, in a similar manner to previous RLE edit distance algorithms, splits the problem into two parts corresponding to shortest paths that pass through the leftmost column or the top row [6, 7, 3, 8]. Consider a mismatch block of height and width corresponding to runs and such that (the other case can be processed similarly by swapping the left and the top part of the input border). and denotes the values of the left and the top part of the input border, numbered in a bottom-to-top and a left-to-right direction, respectively. For an array and a parameter , let . Chen and Chao separately compute all the output border values that are derived from a value in the left part of the input border, denoted , and similarly compute all the output border values that are derived from a value in the top part of the input border, denoted , as follows.
[TABLE]
We start with reformulating the algorithmic framework of Chen and Chao using the following notation.
Definition 2.2**.**
Let be a 1-indexed array of length .
- •
For a parameter , returns the array of length .
- •
* returns the two subarrays , and .*
- •
* returns with the gradient decreased/increased by one, or formally .*
- •
For an integer constant , returns with every value increased by .
- •
* returns an array of length initially filled with zeroes.*
- •
* simply concatenates two arrays.*
Now, equations (1) and (2) can be rephrased as Algorithms 1 and 2, respectively. The final step of the algorithm is to compute the output border as the minimum of and for each index . This is performed in linear time per block by Chen and Chao [8]. In Section 3 we will design a new implementation of both algorithms and a subtle amortised argument for this final step. The latter is based on the fundamental property of the values in an output border summarised by Lemma 2.3.
Lemma 2.3** ([8, Lemma 7]).**
If there exists an such that , then for all .
Before we go on to explain how we speed up the task of deriving the borders of blocks, it is worth exploring for a moment why we cannot simply apply, perhaps with some small modifications, the known time solution for LCS on RLE strings [2]. The key obstacle comes from the different nature of optimal paths in the dynamic programming table of the LCS and edit distance problems.
For the LCS problem on RLE strings Apostolico et al. [2] introduced two important concepts. The first is forced paths and the second corner paths. They say that a path beginning at the upper-left corner of a match block is forced if it traverses the block by strictly diagonal moves and, whenever the right (respectively, lower) side of an intermediate match block is reached, proceeds to the next match block by a straight horizontal (respectively, vertical) line through the mismatch blocks in between. A corner path is one that enters match blocks in the top left corner and exits only through the bottom right corner. They show that there is always a longest common subsequence between two strings corresponding to the concatenation of subpaths of corner and forced paths. This fact greatly reduces the number of different paths that have to be considered and hence the complexity of solving the overall LCS problem. However for the edit distance problem this property of forced paths no longer holds. Figures 3 and 3 show an example of this key difference between optimal paths under edit distance and LCS. In Figure 3 we can see that there is no optimal vertical (or horizontal) path through the mismatch block. By contrast, there is indeed an optimal vertical path for the LCS problem as illustrated by Figure 3.
In order to speed up edit distance computation on RLE strings we introduce a new data structure for input borders and output borders. This will allow us to derive the values of output borders from their respective input borders in amortised logarithmic time per border, rather than the previous linear time. The rest of the paper is devoted to this task.
3 Efficient Manipulation of Piecewise-Linear Functions
In this section, we describe the data structure we will use to represent input borders and output borders in the dynamic programming table. We will then show how the operations from Definition 2.2 can be implemented efficiently using this data structure.
Recall that a piecewise linear function is a real-valued function whose domain is a closed interval that can be represented as a union of closed intervals such that restricted to is an affine function ( for some coefficients and ). The input and output borders as defined in Section 2 are by definition piecewise linear.
In this section, we impose a few further restrictions:
- •
For each integer , the value is also an integer.
- •
The gradient of each is , [math], or .
- •
The endpoints of are integers or half-integers.
The graph of a piecewise linear function is a simple polygonal curve, and thus it can be interpreted as a sequence of turning points connected by straight-line segments. Due to the restrictions imposed on , each turning point has integer or half-integer coordinates. We represent such a function as a sequence of segments stored in an annotated balanced binary search tree, where each segment explicitly keeps the coordinates of its endpoints.111Note that the coordinates of each internal turning point are stored with both incident segments.
We first provide a simple implementation of curves supporting a few basic operations, and then we gradually augment it to handle more complicated operations. We conclude with an amortised running time analysis.
3.1 Basic Operations
Our first implementation just stores the corresponding segment for each node :
:
The coordinates of the left endpoint of the segment corresponding to .
:
The coordinates of the right endpoint of the segment corresponding to .
Nevertheless, we are already able to implement some operations useful in Algorithms 1 and 2.
Create
The create operation produces a function whose graph consists of just one segment with given endpoints and . This enables us to implement the whole of line 4 of Algorithm 1 in worst-case constant time.
Join
The join operation takes two functions, and with domains and , respectively, and with a common endpoint . It returns a function with such that and . To implement this operation, we first join the two balanced binary search trees. If the rightmost segment of has the same gradient as the leftmost segment of , we also join these segments. The resulting tree represents . The worst-case running time is logarithmic.
Split
The split operation takes a function with and a value . It returns two functions and . To implement it, we first descend the binary search tree to find a segment with . If lies in the interior of , we split this segment into two. Next, we split the binary search tree to separate the segments to the left of from the segments to the right of . The resulting two trees represent and , respectively. The worst-case running time is logarithmic.
Combine
The combine operation takes two functions and over the same domain and returns their pointwise minimum: a function with such that for . We assume that there exists such that if and if .
If , then . Hence, we return and discard . Similarly, if , then . Hence, we return and discard .
Otherwise, we are guaranteed that . Our first task is to find . For this, we locate segments of and of such that .
We observe that corresponds to the leftmost node in the BST of such that . Hence, we perform a left-to-right in-order traversal of the BST to find . For each visited node , we evaluate by descending the BST of to find a segment whose domain contains . Symmetrically, corresponds to the rightmost node in the BST of such that , so we find by performing a right-to-left in-order traversal of the BST.
Next, we note that is the leftmost common point of and . Hence, we can now compute easily (the restrictions on and guarantee that it is an integer or a half-integer). Finally, we split both and at , discard and , join with , and return the resulting function as .
As far as the running time is concerned, the cost is logarithmic for each discarded segment. We can now also implement the final combine step that produces our representation of the output border from the outputs of Algorithms 1 and 2 by finding the minimum at each index.
3.2 Shifts
Next, we extend our data structure to implement the shift operation which moves the whole function by a given vector. It is useful in Algorithms 1 and 2 for altering and .
Formally, given a function with and a vector , we transform into such that for each .
This update is performed using a technique known as lazy propagation. We augment each node with the following extra field:
:
A deferred shift to be propagated within the subtree of .
This change is then lazily propagated as further operations are executed. Here, we rely on a key structural property of BST operations:
Observation 3.1**.**
The execution of every BST operation can be extended (at the cost of an extra multiplicative constant in the running time) with a sequence of node activations and deactivations such that:
- •
a node is accessed only when it is active and has no active descendant,
- •
when is active, then all its ancestors are active,
- •
no node is active at the beginning and the end of the execution.
The idea behind lazy propagation is that the deferred updates stored at a node are propagated when is activated. This way, every active node has no delayed updates pending. Hence, from the perspective of any other operation, the effect is the same as if we have meticulously modified every node for each update.
The shift propagation is very simple: when a node receives a request for a shift by , then we just add to the delayed shift stored at . Upon activation of , we propagate to the children of , add to both and , and reset . To implement the shift operation, we just send a request for a shift by to the root node .
The worst-case running time of a shift is constant, and the extra cost of propagation does not increase the asymptotic running time of the remaining operations.
3.3 Gradient Changes
The gradient change operation takes a function and a coefficient , and it transforms into such that for each . This operation is needed in both Algorithms 1 and 2 to transform and , respectively.
We first note that the constraints imposed on the gradients of functions and yield that , is non-decreasing, and is non-increasing, or , is non-increasing, and is non-decreasing. However, these limitations only become relevant in Section 3.4.
To implement gradient change, we just add another field to each node :
:
A deferred gradient change to be propagated within the subtree of .
We now have two types of lazily propagated updates: shift and gradient change. These two operations do not commute, so we need decide how to interpret the two kinds of deferred updates stored at a node . We shall assume that the gradient change by is to be performed before the shift by .
Thus, while shift propagation is implemented as in Section 3.2, adding to is insufficient when a node receives a request to change gradient by : we also need to add to . This approach is correct since a shift by followed by a gradient change by is equivalent to a gradient change by followed by a shift by .
Upon activation of , we first apply the deferred gradient change: we propagate it to the children of , increase by and by , and reset . Then, we handle the deferred shift as in Section 3.2.
Finally, we note that to implement the gradient change operation, we just send a request for a gradient change by to the root node . The worst-case running time is constant.
3.4 Sliding Window Minima
We can finally show how to implement the SWM operation efficiently on our data structure. This is the most involved of the operations we will need. The SWM operation given a function with and a window width , returns a function with such that .
Combinatorial Properties
We begin by observing that the SWM operation is composable.
Observation 3.2**.**
Every function and positive window widths satisfy .
Hence, instead of applying for an integer width , we may equivalently apply the operation times. The key property of width is that the changes to the transformed function are very local. The structure of these modifications can be described in terms of types of turning points. We classify internal turning points by the gradients (Increasing, Flat, or Decreasing) of the incident segments; see Table 1, where we also analyse how a function changes in the vicinity of each turning point subject to .
- •
A point of type FD or DF remains intact.
- •
A point of type FI or IF is shifted by .
- •
A point of type ID is shifted by .
- •
A point of type DI transformed into a point of type DF and a point of type FI, and the latter is shifted by .
Note that the behaviour of DI points is unlike that of other types. However, this discrepancy disappears if we replace every DI point with two coinciding points of types DF and FI, respectively, with an artificial length-0 segment in between. Hence, whenever a new internal turning point is created (which happens only within the join operation), if the turning point would be of type DI, we pre-emptively replace it by two coinciding points of type DF and FI, respectively. Note that the resulting length-0 segment never changes its gradient since gradient change is allowed only on a monotone function. However, when an incident segment is modified, we may need to remove the length-0 segment. This process cannot cascade, though, causing another length zero segment to be removed.
Next, we analyse in Table 2 how the operation affects the endpoints of the graph of . In most cases, the left endpoint stays intact and the right endpoint is shifted by . The only exceptions are endpoints of type -I and D-, which exhibit similar behaviour to the internal turning points of type DI. Moreover, this discrepancy also disappears if we introduce artificial flat segments of length 0. Hence, we replace a point of type -I with two points of type -F and FI, respectively, and a point of type D- with two points of type DF and F-, respectively. However, this time the replacement is not pre-emptive: we perform it as the first step in the implementation of the SWM operation. This is possible because there are just two endpoints, while the number of internal turning points of type DI could be large. Our gain, on the other hand, is that we avoid length-0 segments changing their gradients.
With the artificial length-0 segments in place, it is now true that the effect of the SWM operation on each turning point can be described as a shift depending only on the type of the point. As a result of these shifts, some segments may disappear as their length reaches 0; in this case, we say that a segment collapses. Only segments of three kinds may collapse:
- •
a segment between a point of type ID and point of type DF;
- •
a segment between a point of type IF and point of type FD;
- •
a segment between a point of type FI and point of type ID;
When a segment collapses, it is removed and the two incident turning points are merged.222Two adjacent segments may collapse simultaneously. In that special case, three subsequent points, of type FI, ID, and DF, respectively, need to be deleted. Each segment of the three affected kinds has the collapse time, defined as the smallest for which makes it collapse (assuming no interaction from incident segments) equal the the Manhattan distance between its endpoints. Note that due to the restrictions on the piecewise linear functions considered in this section, the collapse time is always an integer.
Implementation
To implement the SWM operation, we augment each node with the following fields:
:
The types of the turning points joined by the segment corresponding to .
:
The amount of a deferred SWM to be propagated within the subtree of .
:
The minimum collapse time among the segments in the subtree of .
Note that the type of each internal turning point is stored twice. Hence, whenever a node type changes, this fact needs to be reflected at both incident segments (and we need to reach the corresponding nodes by descending the BST; shortcuts would violate 3.1).
The field is of a kind we have not encountered yet: its value depends on the corresponding values for the children of and on other fields at . It is brought up to date whenever is deactivated (so that it can be accessed only when is inactive). We shall assume that its value already reflects the deferred updates stored at . The procedure of recomputing is simple: we determine the collapse time of the segment represented by (which is infinite or equal to depending on the types of the incident turning points), and take the minimum of this value and for every child of . Since has no deferred changes when it is deactivated, the resulting minimum is .
Propagation
The main structural modification to the lazy propagation procedures is that we maintain an additional invariant that no deferred changes are stored on the leftmost and on the rightmost path of the BSTs representing every function . To maintain this invariant, immediately after lazily updating of the whole (sending a request to the root node ), we descend to the leftmost and to the rightmost segment ; this increases the cost of shift and gradient change to logarithmic. Note that the split operation must anyway visit the nodes representing the new boundary segments (to update the types of new endpoints). Moreover, if a path from the root to a given node contains no deferred updates, then this is still true after any rebalancing of the BST (as only active nodes get rotated).
Concerning the lazy SWM propagation, we explicitly forbid requesting for SWM with window width exceeding , because collapsed segments need to be removed before we proceed further. Also, the window widths (and hence the values ) are always non-negative.
We have three kinds of deferred updates now: SWM, gradient change, and shift. We fix the semantics of the fields , , and so that an SWM of width is performed first, a gradient change by second, and a shift by last. The requests for a shift and for a gradient change are still implemented as in Section 3.3; note that these updates do not affect the collapse times (the three segment kinds with finite collapse times cannot appear in monotone functions). On the other hand, the request for an SWM with a window width requires more care. We clearly need to increase by and decrease by the same amount. The aforementioned steps suffice if . Otherwise, we note that the turning points in the subtree of are all of types DF and FD or all of types IF and FI. (Observe that there are no deferred changes in the proper ancestors of and that is not on the leftmost or rightmost path in this case.) We can easily distinguish the two cases by analysing the endpoints of the segment corresponding to . Moreover, the SWM operation is void in the first of these cases, and in the second one it reduces to a shift by . Hence, we shall implement it this way rather than by modifying .
The propagation itself is relatively easy: upon activation of a node , we first propagate the SWM operation to the children of , update the endpoints of the segment corresponding to (according to Tables 1 and 2, with the shift multiplied by ), and finally reset . Then, we propagate the gradient change and the shift. This is implemented as in Section 3.3 except that the gradient change now affects not only the coordinates but also the types of the segment’s endpoints.
SWM Procedure
To implement the SWM procedure itself, we first check the endpoint types and perform appropriate substitutions for endpoints of type -I and D-. Next, we would like to lazily apply the SWM operation with window width to the root . However, this could result in negative collapse time , so instead we perform SWM gradually based on 3.2. If , we make a request for SWM with window width just , leaving the remaining quantity for later on. This already results in , which indicates that there is a collapsed segment. We descend the tree to find such a collapsed segment (activating nodes on the way there and deactivating them on the way back), and take care of this segment appropriately (this may affect neighbouring segments as well). We repeat the process as long as . Once this value is positive again, we are ready to proceed with further application of SWM.
As far as the the running time is concerned, the cost of SWM consists of a logarithmic term for visiting the endpoints and further logarithmic terms for each collapsed segment.
3.5 Complexity Analysis
We complete this section by showing that the aforementioned operations run in amortised logarithmic time.
Lemma 3.3**.**
A sequence of operations on piecewise linear functions takes time.
Proof.
Our potential is multiplied by the total number of turning points in all the stored functions. First, we observe that this potential grows by : each operation creates a constant number of new turning points. In particular, the total number of turning points is , so manipulating BSTs takes time. Next, we note that the worst-case running time of most operations is , with extra time needed for each discarded or collapsed segment. However, every such segment decreases the potential by . ∎
4 An time RLE Edit Distance Algorithm
As in the previous algorithm by Chen and Chao [8], we go through the dynamic programming table block by block. For every block, we transform the representation of its input border to the representation of its output border. As mentioned earlier, borders are piecewise linear with gradient or [math] so they can be maintained in the structure described in Section 3. We will assume that the left and the top part of the input border of every block are stored in separate structures. We start by generating the structures corresponding to the left and the top border of the whole dynamic programming table. These left and top borders are each a single decreasing and increasing sequence, respectively. As a result, we can generate the data structure for the parts corresponding to all blocks trivially in time using create operations. Now, we have to describe how to obtain the structure corresponding to the right and the bottom part of the output border of the current block given the structures corresponding to the left and the top part of its input border. We stress that any structure will be created and then used once as an input to a further operation, which is crucial for the amortisation argument within Lemma 3.3.
Recall that the semantics of split and join operating on arrays in Section 2 and of split and join operating on piecewise linear functions in Section 3 is slightly different: split now creates two functions that both contain the value of the original function at ; symmetrically, join takes two functions defined on and that share the same value at . This is, however, not an issue because the cases in both (1) and (2) overlap at the boundaries.
For a match block, the value stored in an element of the output border is a copy of the value stored in the corresponding element of the input border. Recalling that is the intersection of the input border with diagonal , this can be readily implemented with a constant number of split and join operations.
For a mismatch block, we need to apply Algorithms 1 and 2, merge the returned solutions by taking the minimum at every position, and finally create separate structures corresponding to the right and the bottom part of the output border with a single split operation. Note that while we have already observed that both input border and output border are piecewise linear with gradient or [math], we need to make sure that the same is true for every function obtained inside Algorithms 1 and 2, and for and in particular.
Lemma 4.1**.**
Every function obtained in Algorithms 1 and 2 is piecewise linear with gradient or [math].
Proof.
Consider Algorithm 1. It is easy to verify that and hence also and are indeed piecewise linear with gradient or [math]. Additionally, is equal to the minimum in and so is non-increasing. Consequently, , , and are all piecewise linear with gradient or [math]. We only need to verify that the same holds for their concatenation. This is true because each of these three parts corresponds to a case considered in (1), and these cases overlap at the boundaries.
Next, consider Algorithm 2. Similarly as above, it is easy to verify that and so also and are piecewise linear with gradient or [math]. Furthermore, is equal to the minimum in and so is non-decreasing. Thus, and are piecewise linear with gradient or [math] and the same holds for their concatenation because the cases in (2) overlap at the boundaries. ∎
We now explain in detail how to implement Algorithm 1. We start with computing and by first calling and then using split. Next, is obtained by applying gradient change and shift to , is obtained by calling create, and is obtained by applying shift to . Finally, is created with two calls to join.
Algorithm 2 is implemented by calling and then using split. Next, is obtained by applying shift to , while is obtained by applying gradient change and shift to . Finally, is created by a single call to join.
Having obtained a representation of and , we call combine to obtain a representation of the output border. Such a call is valid due to Lemma 2.3. The overall number of operations on structures is , making the final time complexity by Lemma 3.3.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Hsing-Yen Ann, Chang-Biau Yang, Chiou-Ting Tseng, and Chiou-Yi Hor. A fast and simple algorithm for computing the longest common subsequence of run-length encoded strings. Information Processing Letters , 108(6):360–364, 2008. doi:10.1016/j.ipl.2008.07.005 . · doi ↗
- 2[2] Alberto Apostolico, Gad M. Landau, and Steven Skiena. Matching for run-length encoded strings. Journal of Complexity , 15(1):4–16, 1999. doi:10.1006/jcom.1998.0493 . · doi ↗
- 3[3] Ora Arbell, Gad M. Landau, and Joseph S. B. Mitchell. Edit distance of run-length encoded strings. Information Processing Letters , 83(6):307–314, 2002. doi:10.1016/S 0020-0190(02)00215-6 . · doi ↗
- 4[4] Arturs Backurs and Piotr Indyk. Edit distance cannot be computed in strongly subquadratic time (unless SETH is false). SIAM Journal on Computing , 47(3):1087–1097, 2018. doi:10.1137/15M 1053128 . · doi ↗
- 5[5] Karl Bringmann and Marvin Künnemann. Quadratic conditional lower bounds for string problems and dynamic time warping. In Venkatesan Guruswami, editor, 56th Annual Symposium on Foundations of Computer Science, FOCS 2015 , pages 79–97. IEEE Computer Society, 2015. doi:10.1109/FOCS.2015.15 . · doi ↗
- 6[6] Horst Bunke and János Csirik. An algorithm for matching run-length coded strings. Computing , 50(4):297–314, 1993. doi:10.1007/BF 02243873 . · doi ↗
- 7[7] Horst Bunke and János Csirik. An improved algorithm for computing the edit distance of run-length coded strings. Information Processing Letters , 54(2):93–96, 1995. doi:10.1016/0020-0190(95)00005-W . · doi ↗
- 8[8] Kuan-Yu Chen and Kun-Mao Chao. A fully compressed algorithm for computing the edit distance of run-length encoded strings. Algorithmica , 65(2):354–370, 2013. doi:10.1007/s 00453-011-9592-4 . · doi ↗
