Abstract 1 Introduction 2 Preliminaries 3 Towards a Polynomial Bound 4 Algorithm Analysis and Specifics 5 Conclusion References

A Constant-Factor Approximation for
Continuous Dynamic Time Warping in 2D

Kevin Buchin ORCID Technical University Dortmund, Germany    Maike Buchin ORCID Ruhr University Bochum, Germany    Jan Erik Swiadek ORCID Ruhr University Bochum, Germany    Sampson Wong ORCID University of Copenhagen, Denmark
Abstract

Continuous Dynamic Time Warping (CDTW) is a robust similarity measure for polygonal curves that has recently found a variety of applications. Despite its practical use, not much is known about the algorithmic complexity of computing it in 2D, especially when one requires either an exact solution or strong approximation guarantees. We fill this gap by introducing a 5-approximation algorithm with running time O(n5) under the 1-norm.

This is the first constant-factor approximation for 2D CDTW with polynomial running time. We extend our algorithm to all polygonal norms on 2, which we subsequently use in order to achieve a (5+ε)-approximation with time complexity O(n5/ε1/2) for CDTW in 2D under any fixed norm. The latter result in particular includes the usual Euclidean 2-norm.

Keywords and phrases:
Continuous Dynamic Time Warping, Curve Similarity, Geometric Approximation Algorithm
Category:
Track A: Algorithms, Complexity and Games
Funding:
Sampson Wong: Supported by the European Union’s Marie Skłodowska-Curie Actions Postdoctoral Fellowship, grant no. 101146276.
Copyright and License:
[Uncaptioned image] © Kevin Buchin, Maike Buchin, Jan Erik Swiadek, and Sampson Wong; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Computational geometry
; Theory of computation Approximation algorithms analysis
Related Version:
Full Version: https://arxiv.org/abs/2605.05917
Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele Puppis

1 Introduction

There exist several desirable properties for curve similarity measures [22, 23], two of which are tolerance to outliers and robustness to different sampling rates. As the Fréchet distance fails to provide the former, whereas Dynamic Time Warping struggles with the latter, these popular measures have drawbacks for applications. Continuous Dynamic Time Warping (CDTW) is an alternative that combines both abovementioned properties by minimising a path integral of distances between continuously and monotonically matched points on two polygonal curves. Our considered CDTW formulation [16, 15, 3, 7, 2, 5] originates from a summed version of the Fréchet distance introduced in [8]. There exist other related definitions [20, 21, 17, 1, 11, 14], and we refer to [7, Section 1] as well as [5, Section 1.1] for brief overviews of these.

On the practical side, the robustness of CDTW and its ability to yield high-quality solutions across different application domains have been observed in experiments [1, 11, 3]. Also, reasonable running times on realistic data have been reported [3, 2]. On the theoretical side, however, CDTW still lacks algorithms that guarantee both a good approximation factor and an efficient running time in 2D and beyond. Many existing approaches are approximations or heuristics that proceed via discretising the input curves [1, 11, 16, 15, 3, 14]. These include a generic additive approximation algorithm [15, 3], and a pseudo-polynomial-time (1+ε)-approximation for 2D CDTW under the Euclidean 2-norm [16]. The latter has running time O(ζ4n4/ε2log(ζn/ε)), where n is the complexity and ζ is the spread of the given polygonal curves. That means the running time depends on the maximum ratio ζ of a pair of curve segment lengths. Such dependencies are typical for discretisation approaches.

A different type of approach, which enables exact computations, propagates functions arising from integration within a dynamic program [6, 15, 7, 2, 5]. This results in a polynomial running time of O(n5) for CDTW in 1D [7]. However, in 2D the algorithmic complexity of computing CDTW is as yet unknown. On the one hand, it has been shown that 2D CDTW cannot even be computed exactly under the 2-norm when restricted to algebraic operations [5]. On the other hand, function propagation approaches have only been made to work with polygonal norms like the 1-norm [2, 5]. These give piecewise linear integrands and piecewise quadratic cost functions similar to 1D. By converging to the unit disk, polygonal norms provide a (1+ε)-approximation for CDTW under the 2-norm without a dependency on the curves’ spread. However, the 2D dynamic program may involve more complicated propagation patterns [5, Section 4.2]. Those have so far prevented any 2D generalisation of the quite technical polynomial-time result that was achieved in 1D.

Our Contributions

We show that we can circumvent the 2D propagation patterns that potentially have an exponential complexity, in exchange for an approximation factor β5. This relies on a new bound for certain CDTW integrals, which we establish in Section 3.1. It is open whether the bound is tight, and any improvement to β would transfer to the following results. Applying this building block, we develop a CDTW algorithm that is outlined in Section 3.2 and then analysed in Section 4. After proving its approximation factor, we bound its time complexity by combining ideas from [7] with novel insights. For CDTW in (2,1) we achieve a 5-approximation with running time O(n5). This is the first polynomial-time constant-factor result for 2D CDTW. We subsequently extend our algorithm from the 1-norm 1 to the class of polygonal norms. This is based on the framework of [5], which we generalise to facilitate approximations for not only the 2-norm 2 but also any other norm on 2. To that end, we exploit that any fixed norm on d is (1+ε)-approximated by a polyhedral norm of complexity O(ε(1d)/2). Here, fixed means that we treat the description complexity of , including the dimension d, as a constant. Putting things together, we obtain an approximation algorithm with factor 5+ε and running time O(n5/ε1/2) for 2D CDTW under any fixed norm and for any ε>0. In the imbalanced case, where one of the given polygonal curves has some smaller complexity mo(n), the term n5 in our time bounds may be replaced by n4m. Note that the guaranteed bounds might be pessimistic. In particular, even if β=5 is a tight bound for the approximated CDTW integrals, it is unclear whether there are any curves for which our algorithm approximates within factor close to β.

On a technical level, we expand the toolbox for CDTW algorithms by demonstrating that an integration-based building block and a tailored function propagation scheme can enable CDTW approximations without discretisations of any form. Combining our techniques with the approach of approximating the Euclidean 2-norm via polygonal norms yields polynomial-time computations for 2D CDTW under 2 without any significant loss of accuracy for the first time. Even though polygonal norms have already been used in [5], no attempt at a fine-grained running time analysis was made there, after highlighting the obstacle that we deal with approximatively here. Furthermore, our running time analysis is more streamlined and insightful than that from [7]. We avoid a large case distinction by identifying core principles behind the complexity of function propagations, which generalise beyond some properties unique to 1D. In addition to advancing the understanding of propagation patterns, this enables an improvement upon previous algorithms: We compute lower envelopes of quadratic pieces in a single pass instead of multiple passes.

2 Preliminaries

A polygonal curve P in a normed real vector space (d,) consists of n consecutive line segments induced by a sequence p0,,pn of vertices, where pipi1 for all i{1,,n}. We write Pi:=p0,,pi, where i{0,,n}, for the prefix subcurves of P. The following definitions are based on [5], which provides a robust CDTW formulation under any norm.

Definition 1 ([5, Definition 1]).

Let P,Q be two polygonal curves in (d,). The measure Continuous Dynamic Time Warping (CDTW) of P,Q under is defined by

cdtw(P,Q):=inf(f,g)Π[0,1](P)×Π[0,1](Q)01f(t)g(t)(f(t)g(t))1dt,

where the sets Π[a,b](P) and Π[a,b](Q) contain all piecewise continuously differentiable functions defined on the interval [a,b] that monotonically parametrise P or Q respectively.

The arc length of P under is P:=i=1npipi1. As the arc length is invariant to reparametrisation, we have abf(t)dt=P for all fΠ[a,b](P). We denote the arc length parametrisation of P with constant speed 1 under by P:[0,P]d.

Definition 2 ([5, Definitions 2 and 12]).

The parameter space of two polygonal curves P,Q under is [0,P]×[0,Q]. Each segment pair of P=p0,,pn and Q=q0,,qm is associated with a cell Ci,j:=[Pi1,Pi]×[Qj1,Qj] in their parameter space, where (i,j){1,,n}×{1,,m}. The north/east/south/west border of Ci,j parametrises along that side of Ci,j, e.g. its north border is [Pi1,Pi]2,t(t,Qj)𝖳.

The monotone matchings of P and Q correspond to monotone paths in parameter space. Let σ:=P+Q, and let Γ(P,Q) be the set of functions γ:[0,σ][0,P]×[0,Q] such that there are parametrisations (f,g)Π[0,σ](P)×Π[0,σ](Q) with γ1(s)=0sf(t)dt and γ2(s)=0sg(t)dt as well as γ(s)1=f(s)+g(s)=1 for all s[0,σ].

Definition 3 ([5, Definition 3]).

Let x,y[0,P]×[0,Q] be two points with xy, i.e. x1y1 and x2y2, for polygonal curves P,Q. An (x,y)-path is a restriction γ^:=γ|[x1,y1] of any function γΓ(P,Q) with γ(x1)=x and γ(y1)=y. It is called optimal for P,Q under if it minimises cost(γ^):=x1y1P(γ^1(t))Q(γ^2(t))dt among all (x,y)-paths. We write opt(x,y) for the cost of such an optimal (x,y)-path.

It is cdtw(P,Q)=opt(𝟎,(P,Q)𝖳) by construction, where 𝟎 denotes the origin. Given a cell border :dom()2, we define its optimum function opt0,:dom()0 by opt0,(t):=opt(𝟎,(t)) for tdom(). In a cell under we further define for each pair of south/west input border 𝒜 and north/east output border a function opt𝒜, by

opt𝒜,(s,t):=opt(𝒜(s),(t))for (s,t)dom(𝒜)×dom() with 𝒜(s)(t).

The optimal paths realising opt𝒜, are characterised by Theorem 4, and possible resulting shapes of these optimal paths within different cells are illustrated in Figure 1.

Theorem 4 ([5, Section 2]).

Let P,Q be two polygonal curves in (2,), and let C be a parameter space cell. There exists a line 2 of positive slope such that for any choice of two points x,yC with xy the following (x,y)-path γ is optimal for P,Q under .

  1. (a)

    If intersects the bounding box Ξ:=[x1,y1]×[x2,y2], then γ traces line segments from x to ξx to ξy to y, where ξx,ξyΞ share a coordinate with x,y respectively.

  2. (b)

    If does not intersect the bounding box Ξ, then γ traces line segments from x to ξ to y, where the single bending point ξ{(x1,y2)𝖳,(y1,x2)𝖳} is the point closest to in Ξ.

Figure 1: Optimal paths from different cells’ south borders to their output borders.

Note that Theorem 4 relies on the usage of norms in Definition 1: The equipped norm measures both distances between curve points and speeds of curve parametrisations [5], while the 1-norm 1 combines these speeds within the CDTW path integral [8, 16, 7, 2, 5]. Also, Theorem 4 only holds in 1D and 2D. See the full version for a 3D counterexample.

3 Towards a Polynomial Bound

The idea behind function propagation approaches for exact CDTW algorithms is propagating costs of optimal paths through the parameter space cells and successively computing optimum functions in a dynamic program. After opt0,𝒜 has been computed for each input border 𝒜 of some cell C, one can use Theorem 4 to determine opt0, for each output border of C. If the CDTW integrands are piecewise linear, as it is the case in 1D [7] or under polygonal norms in 2D such as the 1-norm or -norm [2, 5], then all optimum functions of borders are piecewise quadratic (cf. [5, Lemma 14]). The central challenge for the running time analysis lies in bounding the total number of quadratic pieces over all optimum functions [20, 17, 7, 5].

3.1 Building Block

In general, the possible propagation patterns and their complexity in terms of how the number of quadratic pieces is growing are still not well understood. The polynomial bound for the exact 1D algorithm relies heavily on the fact that the quadratic pieces on the output borders of a cell can be assigned monotonically to parent pieces on the cell’s input borders (cf. [7, Lemma 13 and Definition 18]). However, this is insufficient on its own already in 2D under the 1-norm: Certain optimal paths originating from Theorem 4b may hypothetically cause an exponential growth of propagated pieces in 2D, even though there is a monotone assignment to parent pieces. In short, the obstacle for bounding the number of pieces occurs when the paths’ bending points move freely within the cell. This yet unresolved issue was highlighted in [5, Section 4.2]. To tackle the absence of means for finding general tight bounds, our approach instead aims to ensure that the complexity created by such paths during the propagation of path costs in the dynamic program remains low. We henceforth call them unhappy paths within this paper.

Definition 5.

Let γ be an optimal (x,y)-path as in Theorem 4. If each bending point of γ lies on or on the boundary of the cell C, then γ is happy w.r.t. . Else, γ is unhappy.

See the fourth cell of Figure 1 for an unhappy path. As our first contribution, we show that the cost of any (unhappy) optimal (x,y)-path γ from Theorem 4b is approximated within factor at most 5 by choosing the worse of the two possible options for the single bending point ξ of γ. This changes whether a path first travels vertically and then horizontally or vice versa, as shown in Figure 2. Note that the paths from Theorem 4a are always happy.

(a) Considered (x,y)-paths.
(b) Curve matching of γxy.
(c) Curve matching of γyx.
Figure 2: Approximable paths and their corresponding curve matchings.

Our technical proof of the following lemma relies – similar to Theorem 4 – on Definition 1 and Definition 3 employing the equipped norm for distances between curve points as well as speeds and arc lengths on each curve. In particular, this allows for a versatile use of the triangle inequality and symmetry of the metric (p,q)pq induced by .

Lemma 6.

Let x,yC be two points with xy, where C is a parameter space cell of polygonal curves P,Q in (d,). Consider the (x,y)-path γxy tracing line segments from x to (x1,y2)𝖳 to y, and the (x,y)-path γyx tracing line segments from x to (y1,x2)𝖳 to y. Their costs under satisfy 1/5cost(γxy)cost(γyx)5cost(γxy).

Proof.

We show only the second inequality, as the first one is entirely symmetric. To make the notation of this proof more concise, we write ps:=P(s)d and qt:=Q(t)d for parameters (s,t)[x1,y1]×[x2,y2] as well as pq¯:=pq for points p,qd.

As γxy and γyx trace horizontal and vertical line segments, Definition 3 implies that their cost integrands on these respective segments correspond to spsqt¯, where s[x1,y1] varies and t{x2,y2} is fixed, and to tpsqt¯, where t[x2,y2] varies and s{x1,y1} is fixed. We thus also use the shorthands px:=px1, py:=py1, qx:=qx2, and qy:=qy2. By applying the triangle inequality and symmetry that are induced by the norm , we then obtain

cost(γyx)cost(γxy) =x1y1psqx¯ds+x2y2pyqt¯dtx2y2pxqt¯dtx1y1psqy¯ds
=x1y1psqx¯psqy¯ds+x2y2pyqt¯pxqt¯dt
x1y1qxqy¯ds+x2y2pxpy¯dt=2pxpy¯qxqy¯.

The final equality holds because the integrands do not depend on the variables s and t, while the integration intervals are of length y1x1=pxpy¯ and y2x2=qxqy¯ respectively. Note that we have y1x1=pxpy¯ due to x,yC for the given cell C, which means that px and py lie on a single curve segment of P. We similarly have y2x2=qxqy¯. Intuitively, the cost difference between γyx and γxy is at most two times the bounding box area of x and y. Together with 0(pxpy¯qxqy¯)2=pxpy¯2+qxqy¯22pxpy¯qxqy¯, we therefore arrive at

cost(γyx)cost(γxy)+2pxpy¯qxqy¯cost(γxy)+pxpy¯2+qxqy¯2,

so it remains to show pxpy¯2+qxqy¯24cost(γxy) in order to get the claimed result.

We consider x2y2pxqt¯dt, which is the first term of cost(γxy), and pick a λ[x2,y2] such that both qxqλ¯pxqx¯ and qλqy¯pxqy¯ hold. This is feasible as follows: If qxqy¯pxqx¯, then λ:=y2 with qλ=qy works. Else, we have qxqy¯pxqx¯ and can pick λ with qxqλ¯=pxqx¯, which implies qλqy¯=qxqy¯qxqλ¯=qxqy¯pxqx¯pxqy¯ via x,yC and the triangle inequality.

We now split the interval [x2,λ] into k subintervals, each of length 1k(λx2)=1kqxqλ¯. For every value t on the i-th subinterval this gives qxqt¯ikqxqλ¯, so together we have

pxqt¯pxqx¯qxqt¯qxqλ¯ikqxqλ¯=kikqxqλ¯if tx2[i1kqxqλ¯,ikqxqλ¯],

which bounds the integrand from below. Summing this over all i{1,,k} yields

x2λpxqt¯dt1kqxqλ¯i=1kkikqxqλ¯=1kqxqλ¯(k1)k2kqxqλ¯=k12kqxqλ¯2.

Since we also have qλqy¯pxqy¯ by choice of λ, we similarly obtain λy2pxqt¯dtk12kqλqy¯2. Putting these together gives a lower bound for the first term of cost(γxy). That means

x2y2pxqt¯dt=x2λpxqt¯dt+λy2pxqt¯dtk12k(qxqλ¯2+qλqy¯2)k14kqxqy¯2

by utilising 2(qxqλ¯2+qλqy¯2)=(qxqλ¯+qλqy¯)2+(qxqλ¯qλqy¯)2(qxqλ¯+qλqy¯)2=qxqy¯2 in the final inequality. Proceeding analogously for the second term of cost(γxy) results in

cost(γxy)=x2y2pxqt¯dt+x1y1psqy¯dsk14k(qxqy¯2+pxpy¯2)k14(pxpy¯2+qxqy¯2)

and hence pxpy¯2+qxqy¯24cost(γxy) as required above, which completes the proof.

 Remark 7.

It remains open whether the factor of 5 is tight in general. The greatest lower bound that we know of occurs already in 1D: Consider px:=0, py:=ϕ+1, qx:=ϕ, and qy:=2ϕ+1, where ϕ:=(1+5)/2 is the golden ratio. This yields a factor of 2ϕ+14.236. By analysing the trade-off between the inequalities in the above proof, one can likely improve the upper bound in 1D from 5 to 2ϕ+1, but closing the gap for d2 seems difficult.

Lemma 6 for the first time allows CDTW approximations without discretisations of any form. Our approximation algorithm is based on the fact that at least one of the paths γxy and γyx is a happy path whenever both x and y lie on borders of the cell C. At first glance, it thus might even seem like simply omitting all unhappy paths in the propagation procedure of the exact algorithm from [5] yields a polynomial-time result for CDTW in 2D with approximation factor β5. However, this is not the case because minimum-cost happy paths lack an important property of optimal paths: One can always choose non-crossing optimal paths (cf. [7, Lemma 11]), whereas minimum-cost happy paths may cross, e.g. as depicted in the final cell of Figure 1. This prevents the previously mentioned monotone assignment of quadratic pieces. To achieve a polynomial bound, we will propagate some unhappy paths while still keeping the resulting complexity low.

3.2 Algorithm Outline

Having established one of the main building blocks, we now provide a conceptual outline of our approximation algorithm, which uses a propagation scheme tailored to Definition 5 and Lemma 6. Although the outline has no requirements on the norm , note that it only seems feasible to computationally deal with the propagated cost functions if they are well-behaved, such as under polygonal norms. We defer the implementation details along with the analysis to Section 4. The dynamic program in Algorithm 1 visits all parameter space cells in layers, starting at C1,1 and ending at Cn,m. For each cell C we store its north, east, south and west border as C.𝒩, C., C.𝒮 and C.𝒲 respectively. An output border of C knows its adjoining input border .adj and its opposing input border .opp. That means C.𝒩.opp:=C.𝒮=:C..adj, so the first three cells of Figure 1 show paths between opposing borders, and the final two cells show the adjoining case. Symmetrically, we thus have C.𝒩.adj:=C.𝒲=:C..opp as well. (Cf. [5, Definition 13].)

Our algorithm computes for every cell border a cost function .apx that 5-approximates the optimum function opt0,. We also store a value hi,j for all (i,j){0,,n}×{0,,m}, which is set to the minimum computed cost from 𝟎 to the north-east corner (Pi,Qj)𝖳 of the cell Ci,j. The base case of the dynamic program in lines 1–2 is as usual: It initialises all costs given by paths that travel either straight horizontally or straight vertically from 𝟎. Then the main loop initialises in lines 6–7 for each cell C the approximate cost functions of its output borders C.𝒩 and C. via straight paths from the cell corners.

Algorithm 1 A 5-approximation for CDTW of polygonal curves P,Q in (2,).

In the following, the costs of optimal paths within C are implicitly given by some choice of as in Theorem 4. Next, lines 8–11 of Algorithm 1 identify the best path from each of the two input borders to the north-east corner of C. See 3(a) for a possible configuration. Our propagation scheme utilises these paths’ costs and starting points, which are passed to the subroutine C.PropagateCosts. This is a difference to previous propagation-based CDTW algorithms [15, 7, 2, 5], although a related idea was stated in [6, Observation 3.3] within the context of the partial Fréchet similarity.

(a) Best paths from input borders to corner 𝒩.
(b) Propagation from border 𝒲 to border 𝒩.
(c) Propagation from border 𝒮 to border .
(d) Final result after propagating 𝒮 to 𝒩.
Figure 3: Example of algorithm steps in case of minH𝒮=h𝒮<h𝒲=minH𝒲.

As outlined in Algorithm 2, every input border 𝒜 of C is then propagated to its adjoining output border using the subroutine .PropagateFromAdjoining, which updates the cost function .apx. It only propagates paths with the same starting point on 𝒜 as its best path to the north-east corner, see 3(b). This may include unhappy paths with that starting point, e.g. as in 3(c), but it omits all other unhappy paths in contrast to exact algorithms. In a final step, at most one input border 𝒜 is propagated to its opposing output border , namely if its best path to the north-east corner is better than the other one. Here, .PropagateFromOpposing updates .apx by computing a lower envelope over all points located on 𝒜 up to its best path’s starting point. See 3(d) for an example result.

Algorithm 2 Subroutines for propagating costs from input to output borders.

4 Algorithm Analysis and Specifics

In Section 4.1 we show that the above algorithm outline gives a 5-approximation for CDTW. Its implementation details and the resulting running time depend on the (polygonal) norm . We first consider 1 in Section 4.2 and afterwards extend our results in Section 4.3. Both the proof of approximation factor and the running time analysis build upon the fact that all approximate cost functions computed by our algorithm are continuous. To show that, one can apply a useful lemma, which says that converging paths have converging costs.

Lemma 8 ([5, Lemma 19]).

Let γ be an arbitrary (x,y)-path, and let (γk)k be a sequence of (xk,yk)-paths converging to γ, which means limk(xk,yk)=(x,y) and limkγk(λ)=γ(λ) for all λ(x1,y1). The limit limkcost(γk) exists and is equal to cost(γ).

Proposition 9.

For every border the function .apx computed by our algorithm is continuous. Moreover, all t,tdom() with t<t satisfy .apx(t)+opt((t),(t)).apx(t).

The proof of Proposition 9 is deferred to the full version. Showing the continuity of .apx through Lemma 8 is similar to the corresponding proof for the optimum function opt0, [5, Theorem 20]. The second property implies that travelling on a border does not improve the computed costs, which justifies the use of the corner costs hi1,j,hi,j1 in Algorithm 1.

4.1 Proof of Approximation Factor

We want to show that the cost of every optimal path from 𝟎 to a cell border is 5-approximated. To that end, we give a formal and more general definition of best paths to a point. We also establish the existence of best paths and that they are closed under taking prefix paths.

Definition 10.

Let 𝒜 be an input border of a cell C, and let yC be some point. A best path from 𝒜 to y is an optimal (𝒜(sy),y)-path γy such that sydom(𝒜) satisfies 𝒜(sy)y and minimises the function s𝒜.apx(s)+opt(𝒜(s),y). If the function value at sy is less than the analogous minimum for the other input border, we call γy a dominating best path.

Lemma 11.

For each input border 𝒜 of a cell C and each point yC there is a best path γy from 𝒜 to y. Now let 𝒜(sy) with sydom(𝒜) be the starting point of γy, and let λ[λy,y1] be arbitrary, where λy:=𝒜(sy)1. Then the prefix path γy|[λy,λ] is a best path from 𝒜 to γy(λ). If γy is dominating, we have that γy|[λy,λ] is dominating as well.

Proof.

Consider the function s𝒜.apx(s)+opt(𝒜(s),y) from Definition 10. By Proposition 9, 𝒜.apx is continuous. Lemma 8 and Theorem 4 imply that sopt(𝒜(s),y) is also continuous. Basic calculus says that their sum is a continuous function attaining its minimum on the closed interval {sdom(𝒜)𝒜(s)y} at some sy.

If any prefix path γy|[λy,λ] of an optimal (𝒜(sy),y)-path γy were not a best path, there would be a better path γλ from 𝒜 to γy(λ). Concatenating γλ with the suffix of γy would yield a better path from 𝒜 to y than γy, a contradiction. Similarly, the existence of a non-dominating prefix path of γy would imply that γy is non-dominating.

This enables us to show that for paths whose costs are not propagated by the subroutines from Algorithm 2 there are propagations of paths with better or approximating costs. In case of opposing borders, we always find better paths and thus do not require any approximations.

Proposition 12.

Let be an output border of a cell C with opposing input border 𝒜:=.opp. It is .apx(t)𝒜.apx(s)+opt𝒜,(s,t) for all (s,t)dom(𝒜)×dom() with st.

Proof.

Let γ be an optimal (𝒜(s),(t))-path. We next distinguish between whether the subroutine .PropagateFromOpposing from Algorithm 2 is called for the given border or not. Assume first that it is called. If ss holds, where s:=argminH𝒜 is given by lines 8–10 of Algorithm 1, then this call yields .apx(t)apxs(t)𝒜.apx(s)+opt𝒜,(s,t). Else, we have s>s and it follows that γ intersects a best path γ from 𝒜 to the north-east corner of C in some point zC, see 4(a). Lemma 11 says 𝒜.apx(s)+opt(𝒜(s),z)𝒜.apx(s)+opt(𝒜(s),z), so that the call yields

.apx(t)apxs(t)𝒜.apx(s)+opt𝒜,(s,t)𝒜.apx(s)+opt𝒜,(s,t).

Assume now that .PropagateFromOpposing is not called. Because of the decisions made in lines 4–5 of Algorithm 2, there necessarily exists a dominating best path γ0 from the other input border 𝒜0:=.adj to the north-east corner of C. The path γ0 intersects all paths from 𝒜 to , including γ. Let z0C be an intersection point of these two paths, and let 𝒜0(s0) be the starting point of γ0. Lemma 11 says 𝒜0.apx(s0)+opt(𝒜0(s0),z0)<𝒜.apx(s)+opt(𝒜(s),z0). Hence, the subroutine call 𝒜0.PropagateFromAdjoining, which occurs in lines 2–3 of Algorithm 2, now results in

.apx(t)apxs0(t)=𝒜0.apx(s0)+opt𝒜0,(s0,t)<𝒜.apx(s)+opt𝒜,(s,t).

In case of adjoining borders, we get a similar result for happy paths, whereas unhappy paths might not intersect any propagated best paths. We can, however, use Lemma 6 to show that all unhappy paths are already approximated by the propagation of the cell corner that is shared by the adjoining borders.

(a) Intersection with best path in case of opposing borders.
(b) Intersection with best path in case of adjoining borders.
(c) Approximation of unhappy path by cell corner path.
Figure 4: Different configurations yielding a path with at worst approximating cost.
Proposition 13.

Let be an output border of a cell C with adjoining input border 𝒜:=.adj. It is .apx(t)𝒜.apx(s)+5opt𝒜,(s,t) for all (s,t)dom(𝒜)×dom().

Proof.

Let γ be an optimal (𝒜(s),(t))-path as in Theorem 4. Assume first that γ is of the form from Theorem 4a. This implies that γ intersects all paths from 𝒜 to the north-east corner of C, either on or otherwise like in 4(b). Let γ be a best such path with starting point 𝒜(s), where s:=argminH𝒜 is given by lines 8–10 of Algorithm 1, and let zC be an intersection point of γ and γ. Lemma 11 says 𝒜.apx(s)+opt(𝒜(s),z)𝒜.apx(s)+opt(𝒜(s),z). Thus, the call .PropagateFromAdjoining from lines 2–3 of Algorithm 2 results in .apx(t)apxs(t)=𝒜.apx(s)+opt𝒜,(s,t)𝒜.apx(s)+opt𝒜,(s,t).

Assume now that γ is of the form from Theorem 4b. By Lemma 6, we then have

𝒜.apx(s)+5opt𝒜,(s,t)=𝒜.apx(s)+5cost(γ)𝒜.apx(s)+cost(γc),

where γc is the (𝒜(s),(t))-path through the shared cell corner c=𝒜(sc) of the adjoining borders 𝒜 and , see 4(c). We obtain 𝒜.apx(s)+cost(γc)𝒜.apx(sc)+opt(c,(t)).apx(t) due to Proposition 9 and the initialisation of .apx in lines 6–7 of Algorithm 1.

We conclude that the conceptual algorithm outline from Section 3.2 indeed gives a CDTW approximation within factor β5. Using the above propositions, this follows by induction. See the full version for a proof of Theorem 14.

Theorem 14.

Any implementation of Algorithm 1 and Algorithm 2 under a norm returns a factor-5 approximation of cdtw(P,Q) for all polygonal curves P,Q in (2,).

As discussed in 7, we do not know whether the factor is tight. Even the value β that is tight for Lemma 6 might not be tight for Theorem 14. It would only transfer if there are curves P,Q with an optimal (𝟎,(P,Q)𝖳)-path that is predominantly unhappy.

4.2 Running Time under the 1-Norm

In this section we specify the details of how to implement our approximation algorithm under the 1-norm 1, and analyse its running time on two curves P,Q of complexity n and m respectively. By definition, we have z1=|z1|+|z2| for z2, meaning the 1-norm is linear on each quadrant of the plane. Every cell border hence contains only O(1) breakpoints where the function tP1(1(t))Q1(2(t))1 switches from one linear function piece to another. It follows that the base case in lines 1–2 of Algorithm 1, which uses straight paths, has piecewise linear integrands and yields O(1) quadratic pieces on each initialised border . Computing all pieces requires O(n+m) time.

Similarly, propagating the costs of straight paths from the cell corners in lines 6–7 yields O(1) initial quadratic pieces per output border of the cell C. We now claim that lines 8–11 of Algorithm 1 take O(NC.𝒮+NC.𝒲) time, where N denotes the number of (maximal) quadratic pieces making up the computed cost function .apx of a border . Note that the costs of optimal paths within C are given by Theorem 4, and a suitable is computable in O(1) time under 1 [5, Corollary 9]. First, we consider the possible starting points of best paths to the north-east corner of C.

Definition 15.

Let 𝒜, be a pair of input and output border, and let (s0,t0)dom(𝒜)×dom() with 𝒜(s0)(t0) be arbitrary. If the function s𝒜.apx(s)+opt𝒜,(s,t0) attains a semistrict 111That means strict to the left and/or to the right, ruling out interior points of constant-valued pieces. local minimum at s0, we say that 𝒜(s0) is a parent candidate for (t0). If .apx(t0)=𝒜.apx(s0)+opt𝒜,(s0,t0) holds, we say that 𝒜(s0) is a parent point of (t0). We call an interval Sdom(𝒜) a parent interval of Tdom() if each (t) with tT has a parent point 𝒜(s) with sS.

This definition builds upon [7, Definition 18], but allows for a more fine-grained analysis: Whereas [7] collects consecutive quadratic pieces into specific subsegments and then introduces a parent relationship for these subsegments, we deal with arbitrary points and intervals.

For a fixed t0, as in lines 8–9 of Algorithm 1, the given function s𝒜.apx(s)+opt𝒜,(s,t0) is piecewise quadratic with N𝒜+O(1) pieces under 1. This is because 𝒜.apx has N𝒜 pieces, and the optimal (𝒜(s),(t0))-paths from Theorem 4 have O(1) bending points whose coordinates may depend linearly on the variable s. Hence, sopt𝒜,(s,t0) has O(1) quadratic pieces by the linearity of 1 on each quadrant. Basic calculus says that (semistrict) local minima of a piecewise quadratic function can only occur at domain endpoints, at breakpoints between pieces, or at points where the derivative is 0. The latter correspond to parabola vertices, see Figure 5.

Figure 5: Local minima of a continuous and piecewise quadratic function.

Overall, there are O(NC.𝒮+NC.𝒲) parent candidates for the north-east corner of C. We can check all of them to find starting points of best paths, as the global minima that exist by Lemma 11 are among the local minima. Thus, computing the required values from lines 10–11 of Algorithm 1 takes O(NC.𝒮+NC.𝒲) time under 1. Moreover, we can reuse this candidate set for opposing propagation since parent points that do not share a coordinate with the child can be chosen from the same set. This is due to the following key lemma that pertains to happy optimal paths.

Lemma 16 (Happiness Lemma).

Let X:={(s,t)S×T𝒜(s)(t)}, where 𝒜, is a pair of input and output border with S×Tdom(𝒜)×dom(). If all (s,t)X have a happy optimal (𝒜(s),(t))-path, it is opt𝒜,(s,t)=ρ𝒜(s)+ρ(t) on X for two univariate functions ρ𝒜,ρ. This always applies in case of 𝒜=.opp and S×T=dom(𝒜)×dom().

Proof.

The function opt𝒜, is obtained by evaluating costs of optimal (𝒜(s),(t))-paths in terms of the parameter pair (s,t)X, and we assume all paths given by Theorem 4 to be happy on X. Consequently, each bending point ξ0 lies on or on the cell’s boundary according to Definition 5. This implies that ξ0 can be expressed in terms of only s or in terms of only t, cf. Figure 1. We evaluate optimal path costs by summing the costs of subpaths, each of which traces a line segment between two points ξ and ξ that are among 𝒜(s), (t) and the paths’ bending points. Definition 3 says that every such subpath cost is a definite integral of some function ψ on the interval [ξ1,ξ1], where ψ is an affine map. We distinguish the following two cases.

  1. 1.

    If the traced line segment lies on or on the cell’s boundary, the corresponding function ψ is fixed and does not depend on s and t. By the Fundamental Theorem of Calculus, the subpath cost is equal to Ψ(ξ1)Ψ(ξ1), where Ψ is an arbitrary antiderivative of the continuous integrand ψ. Due to happiness, the term Ψ(ξ1) may depend only on s and can thus be assigned to ρ𝒜, while Ψ(ξ1) may depend only on t and can be assigned to ρ.

  2. 2.

    Otherwise, the traced segment is horizontal/vertical with ξ=𝒜(s) or ξ=(t) such that ψ depends only on s or only on t. Then the other endpoint must depend on the same parameter, i.e. ξ depends on s or ξ depends on t. Due to happiness, it can be expressed in terms of only this parameter. The subpath cost can hence be assigned to ρ𝒜 or ρ respectively.

It remains to show that every (x,y)-path γ for x,y on opposing borders is happy. Since paths from Theorem 4a are always happy, we assume that γ is as in Theorem 4b and consider the single breaking point ξ of γ. By construction, ξ shares one coordinate value with x and another with y. Opposing borders parametrise via the same coordinate and keep the other fixed, cf. Definition 2. It follows that the value of ξ in the non-parametric coordinate is equal to one border’s fixed value. This means that ξ lies on the related border and thus on the boundary of C, so γ is happy.

Being able to split costs into two univariate functions simplifies the behaviour of local minima in terms of one variable, which yields the desired characterisation of parent candidates.

Proposition 17.

Let 𝒜 be an input border of a cell C, and let S𝒜 be defined as follows:

S𝒜:={sdom(𝒜)𝒜(s) is a parent candidate for the north-east corner of C}.

Let t0dom(), where is the opposing output border of 𝒜. For every sS𝒜 with st0 we have that 𝒜(s) is a parent candidate for (t0). Conversely, each parent candidate 𝒜(s0) for (t0) satisfies s0{sS𝒜st0}{t0}. It is |S𝒜|O(N𝒜) under 1.

Proof.

We start with the bound for |S𝒜| under 1. As argued above, for a fixed t0dom() the function s𝒜.apx(s)+opt𝒜,(s,t0) from Definition 15 is piecewise quadratic with N𝒜+O(1) pieces under 1. Apart from domain endpoints and piece breakpoints, each piece can contribute at most one semistrict local minimum with derivative 0, so we have |S𝒜|O(N𝒜). In general, we have 𝒜.apx(s)+opt𝒜,(s,t0)=𝒜.apx(s)+ρ𝒜(s)+ρ(t0) for all sdom(𝒜) with st0, where ρ𝒜,ρ are as in Lemma 16. Because ρ(t0) does not depend on the variable s, all local minima that the function attains on the interior of its domain are entirely determined by 𝒜.apx and ρ𝒜. The same applies to the fixed left endpoint of the domain, while the right endpoint is exactly t0 per the constraint st0 of monotone paths. Hence, it is the only parent candidate that can vary. The north-east corner of C gives the largest domain, so the stated results follow.

The intuition behind s0S𝒜 versus s0=t0 for opposing propagation is that the corresponding paths may switch between the two types depicted in the second cell of Figure 1: Either they are straight with s0=t0, or they travel on after starting at a point 𝒜(s0) with s0S𝒜. In fact, this switching is a major reason behind the O((n+m)5) time complexity of the exact 1D algorithm [7]. Note that in 1D the CDTW integrand is 0 everywhere on . The procedure from [7] propagates from 𝒜 to , performs a cumulative minimum operation on , and then propagates from to . In 2D a cell C is generally associated with two non-parallel curve segments, so that the CDTW integrand is non-zero within C except at the point that corresponds to their intersection. Although the cumulative minimum operation can be adapted to non-zero weightings (cf. [7, Observation 46]), Lemma 16 reveals the underlying principles and generalises them to all happy paths. This technical contribution of ours advances the understanding of function propagations. It allows us to streamline and enhance the running time analysis compared to [7], yet it does not hold for unhappy paths. Their propagation complexity is still unknown in 2D, see [5, Section 4.2].

We now continue with the implementation of the subroutines from Algorithm 2 under the 1-norm 1. In .PropagateFromAdjoining the function .apx gets updated through taking its lower envelope with the function apxs defined by t𝒜.apx(s)+opt𝒜,(s,t) on dom(). The given value s provides a fixed starting point for propagated paths, which may include unhappy paths. As fixing the first argument of opt𝒜, is symmetric to fixing its second argument, we have that the function apxs is piecewise quadratic with O(1) pieces under 1. Moreover, .apx has O(1) pieces before the subroutine calls in lines 2–3 of Algorithm 2 occur, so taking the lower envelope requires finding only a constant number of intersections between pieces as in Figure 7.

Figure 6: Intersection between
piecewise quadratic functions.
Figure 7: Monotone assignment of
intervals on to parents on 𝒜.

In .PropagateFromOpposing the cost function .apx then gets updated through taking its lower envelope with the function apxs defined by tminssst𝒜.apx(s)+opt𝒜,(s,t) on dom(). The function apxs is itself a lower envelope, and Proposition 17 implies that it is covered by optimal paths starting at the parent candidates from {sS𝒜ss} together with straight paths starting before 𝒜(s). The costs of the former paths are given by O(N𝒜) functions under 1, each of which again has O(1) quadratic pieces. The latter paths’ costs are given by the function t𝒜.apx(t)+opt𝒜,(t,t) for ts, which has at most N𝒜+O(1) pieces.

The lower envelope of these pieces with the existing O(1) pieces on is computable in linear time since the new pieces are given monotonically by parent points. Those induce intervals on that have parent intervals on 𝒜 separated by S𝒜, see Figure 7. We traverse 𝒜 in ascending order, and compare pieces on given by the current and an earlier interval on 𝒜. In contrast to previous algorithms [7, 5], we do a single bottom-up pass on instead of repeated top-down passes. As it takes O(N𝒜) time to perform an opposing propagation under 1 with this method, lines 8–11 of Algorithm 1 take O(NC.𝒮+NC.𝒲) time in total. We can sum this bound over all cells.

Lemma 18.

Let t0dom() for an output border with opposing input border 𝒜:=.opp, and let 𝒜(s0) be the starting point of a best path from 𝒜 to (t0) with smallest s0. It is

𝒜.apx(s0)+opt𝒜,(s0,t)<𝒜.apx(s)+opt𝒜,(s,t)whenever s<s0t.

In particular, for all ts0 we have that every parent point 𝒜(s) of (t) satisfies ss0.

Proof.

Because 𝒜(s0) is the starting point of a best path to (t0), Definition 10 says 𝒜.apx(s0)+opt𝒜,(s0,t0)𝒜.apx(s)+opt𝒜,(s,t0) for all st0. If s<s0, this holds with strict inequality since there is no such point 𝒜(s) by choice of s0 as the smallest possible value. Using Lemma 16 therefore gives 𝒜.apx(s0)+ρ𝒜(s0)+ρ(t0)<𝒜.apx(s)+ρ𝒜(s)+ρ(t0) for all s<s0. By subtracting ρ(t0) from that inequality, adding ρ(t) for a ts0, and using Lemma 16 once more, we get 𝒜.apx(s0)+opt𝒜,(s0,t)<𝒜.apx(s)+opt𝒜,(s,t) for all s<s0 as desired. Thus, there is no parent point 𝒜(s) of (t) with s<s0 due to Proposition 12.

Proposition 19.

Let be an output border with opposing input border 𝒜:=.opp. We can perform .PropagateFromOpposing in O(N𝒜) time under 1. Algorithm 1 then has a running time in O(N), where N is the total number of quadratic pieces over all cell borders.

Proof.

In the following, we describe a procedure that computes the lower envelope apxs for the subroutine, where sdom(𝒜) is the value passed to its call. Let s1,,sλ be the elements of the set {sS𝒜ss} in ascending order, where S𝒜 is as in Proposition 17. We have w.l.o.g. that the inclusion sS𝒜 holds, which further implies sλ=s. This is since s gives a global and thus also a local minimum: Its computation in lines 8–10 of Algorithm 1 and the decisions made in lines 4–5 of Algorithm 2 mean 𝒜(s) is a parent point of the north-east cell corner.

We partition the interval {sdom(𝒜)ssλ}, which contains all starting points considered by apxs, into subintervals S1:={sdom(𝒜)ss1} and Sκ:=(sκ1,sκ] for κ{2,,λ}. Given a subset Tκdom() with parent interval Sκ for any κ{1,,λ}, Proposition 17 implies that the pieces of apxs on Tκ are those of the function τκ defined by t𝒜.apx(t)+opt𝒜,(t,t) for tSκ and t𝒜.apx(sκ)+opt𝒜,(sκ,t) for t>sκ. See Figure 7 for an example. To compute the lower envelope of τ1,,τλ, it is not necessary to create all pieces of these functions. Instead, we traverse S1,,Sλ and create pieces on the fly through maintaining an active function.

Initially, τ1 is active on all of S1. For κ{2,,λ} we compare the restriction τκ|Sκ with the yet active function τμ by checking their overlapping pairs of pieces for intersections as in Figure 7. This takes O(1) time per pair. If τμ is nowhere greater than τκ on Sκ, then τμ remains active there. Otherwise, τμ only stays active up to the earliest point after which τκ is smaller. At this point τκ becomes active and stays so on the remainder of Sκ. After Sλ has been processed, the traversal is complete and the last active function τμ stays so on the remaining part of the domain.

This procedure correctly constructs the lower envelope: Let 𝒜(s0) be the earliest starting point of a best path to an arbitrary point (t0), and let κ{1,,λ} with s0Sκ. By Proposition 17, all sets of parent candidates are finite. Hence, Lemma 18 and continuity of s𝒜.apx(s)+opt𝒜,(s,t), cf. the proof of Lemma 11, imply that each ts0 has a smallest st[s0,t] such that 𝒜(st) is a parent candidate for (t). Together with the definition of Sκ, we get τκ(t)=𝒜.apx(st)+opt𝒜,(st,t)𝒜.apx(s0)+opt𝒜,(s0,t)<min{τ1(t),,τκ1(t)} for all ts0, while τκ becomes active.

Furthermore, at most N𝒜+O(|S𝒜|) overlapping pairs of pieces are created under 1, which yields a running time in O(N𝒜) by Proposition 17. This is because τ1|S1,,τλ|Sλ together have at most N𝒜+|S𝒜|+O(1) pieces, and we create at most |S𝒜|+O(1) pieces of τμ|Sκ with μ<κ over all active τμ due to the starting points then being fixed to sμ. It remains to update .apx, which already contains O(1) pieces, through taking its lower envelope with the pieces of apxs in O(N𝒜) time.222Alternatively to updating .apx at the end, one can instead construct an initial active function τ0 using its existing pieces, and start comparisons on S1. (Due to the separation of pieces that is explained in the proof of Lemma 24). Altogether, we perform .PropagateFromOpposing in O(N𝒜) time, so that Algorithm 1 takes O(NC.𝒮+NC.𝒲) time per cell C by what has been argued above in this section. Summing this bound over all cells finally yields a total running time in O(N) under 1.

The central challenge is to bound the number N polynomially in the complexities n,m of the input curves. As indicated by the above proof, Lemma 18 implies NN𝒜+O(|S𝒜|) under 1, but combining that with |S𝒜|O(N𝒜) from Proposition 17 is still too weak. It cannot rule out an exponential growth since it allows constants c>1 with NcN𝒜. This necessitates a better bound for |S𝒜| that does not depend on N𝒜. We show that |S𝒜| grows at worst quadratically over successive propagations between opposing borders. The resulting inductive bound for N is our main ingredient for establishing that N is polynomial.

Definition 20.

We assign each border a rank. If .PropagateFromOpposing is not called for , it has rank 0. Else, it has rank r:=r0+1, where r00 is the rank of .opp.

Lemma 21.

Let be an output border of rank r>0 with opposing input border 𝒜:=.opp. Then the number N is bounded by NN𝒜+O(|S𝒜|) with |S𝒜|O(r2) under 1.

Lemma 21 follows from the more general Lemma 24 that we will prove below in Section 4.3. In comparison to [7, Lemma 14], the proof of our bounds avoids a distinction between different types of subsegments. It instead uses the Happiness Lemma to implicitly handle all types that are relevant for our algorithm. With these bounds in place, it remains to count the number of quadratic pieces on a border as well as the number of borders for each rank.

Proposition 22.

In a parameter space with n×m cells the ranks are at most max{n,m}. There are O(nm) borders of rank 0, each of which has O(1) quadratic pieces under 1. There are O(nm/r) borders of any rank r>0, each of which has O(r3) pieces under 1.

Proof.

The first claim is true since ranks can only accumulate along a row or column of cells by Definition 20. As there are O(nm) borders in total, this particularly holds for borders of rank 0, and we have already argued in this section that these borders have O(1) pieces under 1. Each border of rank r>0 has r predecessor borders of ranks 0,,r1 that are disjoint from all the other predecessors, so the number of rank-r borders is in O(nm/r). Finally, we show Nc2r3 by induction, where c is a universal constant for the bounds of Lemma 21. In the base case for r=1, only one propagation from a border of rank 0 with O(1) pieces has occurred. For the inductive step we assume r=r0+1, where r0>0 is the rank of 𝒜:=.opp. By using Lemma 21 and the induction hypothesis for 𝒜, we get

NN𝒜+c|S𝒜|c2r03+c(cr2)c2r2(r0+1)=c2r3.

When putting it together, we assume nm in order to bound the maximum rank by n. This is not a restriction since the input curves P,Q can be swapped: We have cdtw(P,Q)=cdtw(Q,P) under any norm , as Definition 1 inherits the norm-induced symmetry.

Theorem 23.

Given polygonal curves P=p0,,pn and Q=q0,,qm in (2,1), where nm, our 5-approximation for CDTW of P,Q under 1 takes O(n4m) time.

Proof.

Proposition 19 says that the running time is linear in N. By Proposition 22, there is a constant c with Nc(nm+r=1nnm/rr3)=cnm(1+r=1nr2)2cn4m.

4.3 Extension to Other Norms

We proceed to extend the above implementation and running time analysis of our algorithm from the 1-norm to general polygonal norms, which we will subsequently use in order to approximate any given norm on 2 such as the 2-norm. For these purposes, we employ the following characterisation: A function is a norm on d if and only if it is the gauge 𝒢K:d0 of a suitable set Kd, defined by 𝒢K(z):=inf{λ0zλK}. E.g., the 2-norm is the gauge of the Euclidean unit ball, and the 1-norm on 2 is the gauge of the convex polygon that has vertices (±1,0)𝖳 and (0,±1)𝖳. The precise conditions for K are that it is absorbing, balanced, bounded and convex. Because the gauge of any such set is equal to the gauges of its closure and interior, one may optionally further require that K is closed or open. (See [19, pp. 39–40].) We defer formal definitions to later.

(a) Tilted square (1-norm).
(b) Square (-norm).
(c) Balanced convex polygon.
Figure 8: Polygons whose gauges are norms, along with evaluation vectors for specific cones.

For now, we only need the linearity property of polygonal norms that allows for the extension. While 1 is linear on each quadrant of the plane, any norm 𝒢K for a suitable polygon K2 is linear on each cone Δv,w:={λv+μwλ,μ0}, where v,w2 are two adjacent vertices of K. In fact, we can evaluate 𝒢K on the cone Δv,w through the scalar product 𝒢K(z)=(w2v2,v1w1)v1w2w1v2z, which uses a vector that is orthogonal to vw. See Figure 8 for examples. This property yields piecewise linear CDTW integrands, and it suffices for proving the generalised inductive bound that we desire. If K is a polygon of complexity k, i.e. it has k vertices and k cones, then the piecewise quadratic functions that had O(1) pieces under 1 have O(k) pieces under 𝒢K.

Lemma 24.

Consider any norm 𝒢K on 2 such that K is a polygon of complexity k, and let be an output border of rank r>0 with opposing input border 𝒜:=.opp. Then the number N is bounded by NN𝒜+O(|S𝒜|+k) with |S𝒜|O(r2k) under 𝒢K.

Proof.

As the considered norm 𝒢K is linear on k cones partitioning the plane, fixing an argument of opt𝒜, now yields a piecewise quadratic function with O(k) pieces, which is one of ρ𝒜,ρ from Lemma 16 plus the fixed offset resulting from the other. This is again because the O(1) bending points of the optimal paths from Theorem 4 may depend linearly on the non-fixed argument, so that the arguments of 𝒢K in the integrand for the path costs can switch cones O(k) times.

For the same reason, the initialisation of .apx in lines 6–7 of Algorithm 1 and the subroutine call .PropagateFromAdjoining from Algorithm 2 result in O(k) quadratic pieces. Some of these pieces may remain after the call .PropagateFromOpposing, but they cannot result in an increase of complexity: Every dominating best path from 𝒜 to a point (t) intersects all paths from .adj to points (t) for t>t. By applying Lemma 11 as in the proof of Proposition 12, it then follows that there are dominating best paths from 𝒜 to all such (t). Thus, the pieces that the two input borders give are separated, and .adj contributes at most O(k) pieces to N. To show NN𝒜+O(|S𝒜|+k), we need to bound the number of pieces given by 𝒜=.opp. For this, we consider the causes that can contribute pieces of apxs. Recall that we have

apxs(t)=minssst𝒜.apx(s)+opt𝒜,(s,t)=ρ(t)+minssst𝒜.apx(s)+ρ𝒜(s)

for all tdom() due to its definition and Lemma 16, so one possible cause is a switch to another piece of ρ. Apart from this, Proposition 17 implies that any new piece of apxs may only begin when our assignment of parent points needs to switch to another piece of 𝒜.apx or to one of ρ𝒜, or when it needs to switch to or from a parent point among the candidates contained in S𝒜. These switches never occur in reverse direction since Lemma 18 says that parent points can be assigned monotonically. Hence, ρ𝒜 and ρ contribute O(k) pieces to N, while 𝒜.apx contributes at most N𝒜 pieces. We charge each parent point from S𝒜 twice to cover the case that it causes a new piece both when switching to it and when switching away from it in a monotone assignment. This contributes at most 2|S𝒜| pieces, so we obtain NN𝒜+O(|S𝒜|+k) as desired.

We next bound |S𝒜|, which is the number of parent candidates for the north-east cell corner. By Definition 15 and Lemma 16, these candidates correspond to the semistrict local minima of the piecewise quadratic function s𝒜.apx(s)+ρ𝒜(s). They can thus only occur at the two domain endpoints, at the breakpoints between pieces, or at points where the derivative is 0. More precisely, a local minimum can occur at some breakpoint only if the left piece’s derivative is at most 0 and the right piece’s derivative it at least 0, see Figure 5. This is because the function is additionally continuous, cf. the proof of Lemma 11. Its left and right derivatives are defined everywhere. Let and + respectively denote the left and right differentiation operator. In the following, we split dom(𝒜) into open intervals such that [𝒜.apx(s)+ρ𝒜(s)]+[𝒜.apx(s)+ρ𝒜(s)] holds on every interval, which implies that local minima attained within them must have derivative 0. For this, we consider the predecessor borders 𝒜0,,𝒜r1 of , where 𝒜r1:=𝒜 has rank r1, and 𝒜i1:=𝒜i.opp has rank i1 for i{1,,r1}. They all share the same domain.

We introduce partition points for our open intervals at the breakpoints of the functions 𝒜0.apx and ρ𝒜 as well as, for all i{1,,r1}, at the breakpoints of ρ𝒜i1 and ρ𝒜i from Lemma 16. These are O(r) functions and each has O(k) pieces, so their breakpoints split dom(𝒜) into O(rk) open intervals. In addition to proving the above property, we determine the number of semistrict local minima with derivative 0 to be at most r on each interval, so we get |S𝒜|O(r2k). Let Idom(𝒜) be one of the open intervals. As 𝒜0.apx has a single piece on I by construction, its left and right derivatives match on all of I. Given i{1,,r1}, we therefore inductively assume 𝒜i1.apx(s)+𝒜i1.apx(s) for all sI, and show that 𝒜i.apx also has this property. For 𝒜r1=𝒜 it then transfers to s𝒜.apx(s)+ρ𝒜(s) since ρ𝒜 has a single piece on I. As for the inductive step: Proposition 17 implies that 𝒜i.apx|I is the lower envelope of

αi:I0,defined byαi(t):=𝒜i1.apx(t)+ρ𝒜i1(t)+ρ𝒜i(t),
as well asαi,s0:{tIts0}0 for all s0S𝒜i1,
defined byαi,s0(t):=𝒜i1.apx(s0)+ρ𝒜i1(s0)+ρ𝒜i(t).

Due to ρ𝒜i1 and ρ𝒜i each having a single piece on I by construction, it follows αi(t)+αi(t) for all tI via the induction hypothesis. Meanwhile, for all s0S𝒜i1 and all tI with t>s0 we even have αi,s0(t)=+αi,s0(t) since the argument of 𝒜i1.apx in αi,s0 is fixed to s0. The lower envelope retains this property: It only switches from one of the functions to another if the next function’s right derivative is less than or equal to the previous one’s. Else, the previous function would still yield smaller values beyond the breakpoint, see Figure 9. Thus, 𝒜i.apx(t)+𝒜i.apx(t) holds for all tI, including the breakpoints introduced by the lower envelope.

(a) Lower envelope switches functions,
which decreases the right derivative.
(b) Lower envelope does not switch functions,
which keeps equal left and right derivatives.
Figure 9: Behaviour of a continuous lower envelope depending on the functions’ derivatives.

It remains to bound the number of semistrict local minima with derivative 0 occurring on I. For this, we count the distinct (a,b)-coefficient pairs over all the quadratic pieces sas2+bs+c of the function 𝒜.apx on I. Such a pair determines the derivative of the pieces to be s2as+b, and thereby fixes the the sole point with derivative 0 to be b/(2a) in case of a0. That means the number of distinct (a,b)-pairs gives an upper bound for the number of parabola vertices. Note that the case of a=0 does not contribute additional semistrict local minima, as it yields a derivative of constant value b. Local minima on I have derivative 0 as argued before, requiring also b=0 and thus constant-valued pieces. Any semistrict minimum on those pieces can only be attained at a piece breakpoint. Such a point then has to coincide either with an endpoint of the open interval I, or with a point of derivative 0 that is fixed by a neighbouring piece’s pair.

We use induction again to prove that 𝒜i.apx has at most i+1 distinct (a,b)-coefficient pairs on I for all i{0,,r1}. The base case for i=0 is true since 𝒜0.apx has a single piece on I. For i>0 we inductively assume that 𝒜i1.apx has at most i such pairs, and we consider 𝒜i.apx in form of the lower envelope from above. Adding ρ𝒜i1 and ρ𝒜i, which both have a single piece on I, to 𝒜i1.apx preserves the number of (a,b)-pairs. Therefore, αi has at most i pairs on I. Moreover, all functions αi,s0 for s0S𝒜i1 share the single (a,b)-pair of ρ𝒜i on I because the terms with fixed arguments contribute to c instead of a and b. Together, we have that 𝒜i.apx has at most i+1 distinct (a,b)-coefficient pairs on I. For 𝒜r1=𝒜 the number r is again preserved by adding the single piece of ρ𝒜 on I, so that we overall have |S𝒜I|r as claimed above.

Note that the ideas of counting (a,b)-coefficient pairs [7, Lemma 14] as well as utilising left and right derivatives [7, Lemma 17] originate from the analysis of the exact 1D algorithm. There, the desired properties and bounds were shown separately on subsegments, which were associated with different types of optimal paths as in Figure 1. This required a distinction into a lot of cases, and it caused the analysis to become large and repetitive. One difficulty was the lack of tools for taking a unified approach and exploiting common principles behind function propagations. Lemma 16 now provides such a tool. Although the subsegments are still reflected by the above proof splitting the domain into intervals, our analysis is much shorter and more straightforward than that from [7]. We believe that this constitutes an insightful contribution to the understanding of propagation complexity. A general analysis of unhappy paths in 2D remains open for future work. The costs of these paths cannot be split into two univariate functions (cf. [7, Section 4.5]).

We next use Lemma 24 to establish that under a polygonal norm 𝒢K of complexity k our algorithm can be implemented with running time O(n4mk). This extension is not difficult, yet there are two important aspects for achieving a linear factor in k instead of a worse factor: First, the fact that the procedure for opposing propagation from Proposition 19 uses a single pass on the output border , which is an algorithmic contribution of ours. Doing multiple passes as in [7, 5] would lead to a higher running time (cf. [5, Proposition 18]). Second, evaluating 𝒢K at a point z2 requires finding the cone of K that contains z. This is possible in O(log(k)) time via binary search. A naive implementation would do this O(k) times per cell to compute costs of optimal paths, which we avoid by keeping track of how the arguments of 𝒢K switch cones. See the full version for a proof of Theorem 25.

Theorem 25.

Consider any norm 𝒢K on 2 such that K is a polygon of complexity k. Given polygonal curves P=p0,,pn and Q=q0,,qm in (2,𝒢K), where nm, our 5-approximation for CDTW of P,Q under 𝒢K takes O(n4mk) time.

To approximate CDTW in 2D under the 2-norm, we may use a regular polygon inscribed in the Euclidean unit disk. This was done in [5, Corollary 17], and a factor of 1+ε requires polygon complexity kO(ε1/2). In fact, results from convex geometry imply that we can approximate any fixed norm on 2 by some polygonal norm of the same complexity. More generally, any fixed norm on d is (1+ε)-approximated by some polyhedral norm of complexity O(ε(1d)/2). In the following, we outline this polyhedral approximation and its application to our results. Its first ingredient is the geometric characterisation of norms, which we have introduced before: A function is a norm on d if and only if it is the gauge 𝒢K of an absorbing, balanced, bounded, convex and closed set K. The first two properties are defined as follows (see [19, p. 11]).

  1. 1.

    A set Kd is called absorbing (or radial) if for every point zd there exists some λ00 such that zλK holds whenever |λ|λ0. This ensures that 𝒢K indeed assigns every zd a real number 𝒢K(z)=inf{λ0zλK}. It further implies 𝟎K.

  2. 2.

    A set Kd is called balanced (or circled) in case of λKK for all λ[1,1]. This yields absolute homogeneity of 𝒢K, i.e. 𝒢K(λz)=|λ|𝒢K(z) for all zd and all λ. If K is a polyhedron, it further implies that K must have an even number of vertices.

The other three properties are defined as usual, and we do not require those definitions here. Every absorbing, convex and closed set in d contains the origin 𝟎 in its interior. When a bounded, convex and closed set in d has a non-empty interior, it is also called a convex body. Moreover, gauges allow describing any norm via its unit sublevel set: We have that is the gauge 𝒢M of the balanced convex body M:={zdz1}. (See [19, p. 40].)

The second ingredient is the approximation of convex bodies by (convex) polyhedra, for which there is a vast amount of literature, see [4] for a survey. Note that a d-dimensional polyhedron K generally has different numbers of vertices and facets when d>2, where the facets correspond to the cones on which the gauge 𝒢K is linear. The specific result that we need holds independent of whether one desires a bound on the number of vertices or facets, though this may lead to distinct polyhedra. Because we do not consider the equipped norm to be an input for CDTW, we suppress all constants in the size and dimension of the given convex body by treating it as fixed.

Lemma 26 ([4, Section 4.4]).

Fix any balanced convex body Md. For every ε>0 there is a convex polyhedron Kd with O(ε(1d)/2) facets (or vertices) and MK(1+ε)M.

For e.g. the sublevel sets of p-norms, which are hyperellipsoids if 1<p<, it is not difficult to determine these approximating polyhedra. Constructions for the general case may involve very large constants, see [4, Section 8] for algorithmic considerations. A simple approach, albeit with a higher worst-case asymptotic complexity, is to choose roughly εdlog(εd) points uniformly at random from the boundary of (1+ε)M. Then their convex hull is a (1+ε)-approximation of M with high probability [18]. Also, note that Proposition 27, which we prove in the full version, might be applicable to other results that work for polyhedral norms, such as the subquadratic DTW algorithm from [12].

Proposition 27.

Fix any norm on d. For every ε>0 there is another norm 𝒢K on d, where Kd is a balanced convex polyhedron with O(ε(1d)/2) facets (or vertices), such that z𝒢K(z)(1+ε)z holds for all zd.

Theorem 28.

Fix any norm on 2, and let ε>0 be arbitrary. Given two polygonal curves P=p0,,pn and Q=q0,,qm in (2,), where nm, we can compute a factor-(5+ε) approximation for CDTW of P,Q under in running time O(n4m/ε1/2).

Proof.

We use Proposition 27 for ε0:=min{ε15,1} to get a norm 𝒢K. By Definition 1, it is

cdtw(P,Q)cdtw𝒢K(P,Q)(1+ε0)2cdtw(P,Q)(1+ε5)cdtw(P,Q).

Applying Theorem 25 to 𝒢K thus returns a (5+ε)-approximation in O(n4m/ε1/2) time.

5 Conclusion

We established the first constant-factor approximation algorithm for CDTW in 2D that has a polynomial running time. It relies on a new integration-based building block and uses a tailored propagation scheme. Another technical contribution of ours is a unified approach to the running time analysis, thanks to novel insights into core principles behind propagation complexity. It is still open whether the additional propagation patterns occurring in exact 2D algorithms, which we circumvented, have polynomial complexity. We also do not know if the approximation factor of 5 is tight, see 7 and Section 4.1. To evaluate efficiency and solution quality in practice, an experimental comparison of an exact algorithm and our approximation algorithm would be useful.

Our algorithm works for all polygonal norms. We demonstrated that this allows to approximate CDTW in 2D under any desired norm, making our results applicable in a very broad 2D setting. Recently, there has been an increased interest in solving not only geometric but also combinatorial optimisation problems under more general norm objective functions, see for example [9, 10]. One advantage of measuring the similarity of curves under a norm of choice is the possibility to assign the curve dimensions, which may carry different types of data, suitable weightings [13]. Thus, higher dimensions are a natural direction for future work on CDTW. Known fundamentals do not suffice there since Theorem 4 does not hold in 3D and beyond, see the full version for a counterexample.

References

  • [1] Sotiris Brakatsoulas, Dieter Pfoser, Randall Salas, and Carola Wenk. On map-matching vehicle tracking data. In Proceedings of the 31st International Conference on Very Large Data Bases, pages 853–864. VLDB Endowment, 2005. URL: https://dl.acm.org/doi/10.5555/1083592.1083691.
  • [2] Milutin Brankovic. Graphs and Trajectories in Practical Geometric Problems. PhD thesis, University of Sydney, 2022.
  • [3] Milutin Brankovic, Kevin Buchin, Koen Klaren, André Nusser, Aleksandr Popov, and Sampson Wong. (k,l)-medians clustering of trajectories using Continuous Dynamic Time Warping. In Proceedings of the 28th International Conference on Advances in Geographic Information Systems, pages 99–110. ACM, 2020. doi:10.1145/3397536.3422245.
  • [4] Efim M. Bronstein. Approximation of convex sets by polytopes. Journal of Mathematical Sciences, 153(6):727–762, 2008. doi:10.1007/S10958-008-9144-X.
  • [5] Kevin Buchin, Maike Buchin, Jan Erik Swiadek, and Sampson Wong. Fundamentals of computing Continuous Dynamic Time Warping in 2D under different norms. In 20th International Conference and Workshops on Algorithms and Computation, pages 467–482. Springer, 2026. doi:10.1007/978-981-95-7127-7_31.
  • [6] Kevin Buchin, Maike Buchin, and Yusu Wang. Exact algorithms for partial curve matching via the Fréchet distance. In Proceedings of the Twentieth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 645–654. SIAM, 2009. doi:10.1137/1.9781611973068.71.
  • [7] Kevin Buchin, André Nusser, and Sampson Wong. Computing Continuous Dynamic Time Warping of time series in polynomial time. Journal of Computational Geometry, 16(1):765–799, 2025. doi:10.20382/JOCG.V16I1A21.
  • [8] Maike Buchin. On the Computability of the Fréchet Distance between Triangulated Surfaces. PhD thesis, Freie Universität Berlin, 2007. URL: https://refubium.fu-berlin.de/handle/fub188/1909.
  • [9] Deeparnab Chakrabarty and Chaitanya Swamy. Approximation algorithms for minimum norm and ordered optimization problems. In Proceedings of the 51st Annual ACM SIGACT Symposium on Theory of Computing, pages 126–137. ACM, 2019. doi:10.1145/3313276.3316322.
  • [10] Kuowen Chen, Jian Li, Yuval Rabani, and Yiran Zhang. New results on a general class of minimum norm optimization problems. In 52nd International Colloquium on Automata, Languages, and Programming, pages 50:1–50:20. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. doi:10.4230/LIPIcs.ICALP.2025.50.
  • [11] Alon Efrat, Quanfu Fan, and Suresh Venkatasubramanian. Curve matching, time warping, and light fields: New algorithms for computing similarity between curves. Journal of Mathematical Imaging and Vision, 27(3):203–216, 2007. doi:10.1007/S10851-006-0647-0.
  • [12] Omer Gold and Micha Sharir. Dynamic Time Warping and Geometric Edit Distance: Breaking the quadratic barrier. ACM Transactions on Algorithms, 14(4):50:1–50:17, 2018. doi:10.1145/3230734.
  • [13] Theodor Gutschlag and Sabine Storandt. On the generalized Fréchet distance and its applications. In Proceedings of the 30th International Conference on Advances in Geographic Information Systems, pages 35:1–35:10. ACM, 2022. doi:10.1145/3557915.3560970.
  • [14] Sariel Har-Peled, Benjamin Raichel, and Eliot W. Robson. The Fréchet distance unleashed: Approximating a dog with a frog. In 41st International Symposium on Computational Geometry, pages 54:1–54:13. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. doi:10.4230/LIPIcs.SOCG.2025.54.
  • [15] Koen Klaren. Continuous Dynamic Time Warping for clustering curves. Master’s thesis, Eindhoven University of Technology, 2020. URL: https://research.tue.nl/en/studentTheses/continuous-dynamic-time-warping-for-clustering-curves.
  • [16] Anil Maheshwari, Jörg-Rüdiger Sack, and Christian Scheffer. Approximating the integral Fréchet distance. Computational Geometry, 70–71:13–30, 2018. doi:10.1016/J.COMGEO.2018.01.001.
  • [17] Mario E. Munich and Pietro Perona. Continuous Dynamic Time Warping for translation-invariant curve alignment with applications to signature verification. In Proceedings of the Seventh IEEE International Conference on Computer Vision, pages 108–115. IEEE, 1999. doi:10.1109/ICCV.1999.791205.
  • [18] Márton Naszódi. Approximating a convex body by a polytope using the Epsilon-Net Theorem. Discrete & Computational Geometry, 61(3):686–693, 2019. doi:10.1007/S00454-018-9977-0.
  • [19] Helmut H. Schaefer and Manfred P. Wolff. Topological Vector Spaces. Springer, 2nd edition, 1999. doi:10.1007/978-1-4612-1468-7.
  • [20] Bruno Serra and Marc Berthod. Subpixel contour matching using continuous dynamic programming. In 1994 Proceedings of IEEE Conference on Computer Vision and Pattern Recognition, pages 202–207. IEEE, 1994. doi:10.1109/CVPR.1994.323830.
  • [21] Bruno Serra and Marc Berthod. Optimal subpixel matching of contour chains and segments. In Proceedings of IEEE International Conference on Computer Vision, pages 402–407. IEEE, 1995. doi:10.1109/ICCV.1995.466911.
  • [22] Han Su, Shuncheng Liu, Bolong Zheng, Xiaofang Zhou, and Kai Zheng. A survey of trajectory distance measures and performance evaluation. The VLDB Journal, 29(1):3–32, 2020. doi:10.1007/S00778-019-00574-9.
  • [23] Yaguang Tao, Alan Both, Rodrigo I. Silveira, Kevin Buchin, Stef Sijben, Ross S. Purves, Patrick Laube, Dongliang Peng, Kevin Toohey, and Matt Duckham. A comparative analysis of trajectory similarity measures. GIScience & Remote Sensing, 58(5):643–669, 2021. doi:10.1080/15481603.2021.1908927.