How this calculation works
Find a minimum accumulated-cost alignment between ordered numeric sequences with an optional index band.
D(i, j)=||ai−bj||²+min[D(i−1, j−1), D(i−1, j), D(i, j−1)].A worked example
The default sequences 0,1,2,3 and 0,1,1,2,3 align at zero squared cost by matching the first sequence’s1 to both repeated 1 observations.
Good to know
1–150 rows per sequence, matching dimensions 1–5, integer band 0–150. Endpoint-to-endpoint alignment with squared Euclidean local costs and horizontal/vertical/diagonal steps. No path within band is rejected; no automatic amplitude or time normalization.
Reference: Müller: dynamic time warping (opens in a new tab) ↗
Aligning order while stretching time
Dynamic time warping aligns two ordered sequences by allowing one observation to correspond to several consecutive observations in the other. The alignment must move forward and connect both endpoints. Its objective is the sum of local matching costs along that monotone path.
This differs from discrete Frechet distance, which minimizes a largest paired distance rather than an accumulated sum. Two alignments can have the same maximum discrepancy but different total costs. A useful calculator must therefore state its objective instead of using the word distance for every sequence-comparison rule interchangeably.
Compare this with the Discrete Frechet distance calculator for two ordered polylines. Minimize accumulated alignment cost over ordered sequences; discrete Frechet minimizes the largest paired distance instead.
Sequence values and local cost
Enter one numeric observation per row or a fixed-dimensional vector per row. Both sequences must have the same number of components per observation. The local cost is the squared Euclidean difference, summed across those components without automatic rescaling or feature weighting.
A high-amplitude component can dominate the score if another component has a much smaller numeric scale. Standardizing features may be appropriate for a particular application, but doing it silently would change the input problem. Prepare any intended normalization before entering the sequences and document that choice alongside the result.
The repeated-value worked example
The default first sequence is zero, one, two, three. The second inserts an extra one between its one and two. A monotone alignment can match the first sequence's one to both occurrences of one, while preserving the other equal-value matches.
Every selected local squared difference is zero, so the accumulated cost is zero even though the sequence lengths differ. This illustrates the intended stretching behavior rather than a failure to penalize missing timestamps. The page does not impose a separate duration or repetition penalty beyond the declared local-cost sum.
Dynamic programming and traceback
Each cell stores the best accumulated cost for aligning the two prefixes ending there. It adds the current local cost to the minimum of three predecessor cells: diagonal, vertical or horizontal. The acyclic grid makes this recurrence a complete finite optimization rather than a heuristic local search.
Predecessor choices are recorded and traced backward from the final cell to recover the path. The implementation recomputes the sum of costs along that returned path and checks it against the dynamic-programming optimum. Multiple optimal paths can exist; the page returns one according to its deterministic predecessor order.
The index-band constraint
A band limits how far paired row indices can differ. A zero-width band allows only equal indices, while a sufficiently wide band permits the full monotone grid. The band is measured in row-index differences, not in physical seconds or a fraction of sequence length.
For unequal lengths, a narrow band can exclude the endpoint pair itself and leave no valid path. That case is reported as no alignment within the supplied constraint. It should not be replaced by a partially aligned prefix and labeled a complete endpoint-to-endpoint distance.
Reading cost and path length
The headline is total squared local cost. The square-root field is simply its square root, while mean path cost divides by the number of selected pairs. These quantities have different interpretations and do not become equivalent just because they derive from the same returned alignment.
Path normalization can also change comparisons between datasets of different lengths. The chosen optimization minimizes the unnormalized sum, not the mean path cost. Dividing the final sum afterward does not prove that the path also minimizes that normalized objective under another definition.
What an alignment cannot establish
A low cost means the sequences can match under the declared monotone stretching rule. It does not prove equal physical dynamics, causal synchronization or a unique timing correspondence. Repeated patterns may allow several very different paths with the same numeric cost.
Inspect the returned index pairs before using the alignment for resampling or labeling. If real timestamps, slope restrictions or penalties for repeated matches matter, use a model that includes them explicitly. This page provides a bounded exact grid calculation with a path certificate, not a universal similarity judgment.
A few questions, answered
Why can different-length sequences have zero cost?
Repeated equal values can be aligned through horizontal or vertical steps without a nonzero local difference.
Is the headline squared cost?
Yes. It sums squared Euclidean local differences; a separate field gives its square root.
Does the band use time units?
No. It limits absolute row-index differences, not elapsed time.
Is mean path cost the optimized objective?
No. The algorithm minimizes total accumulated cost; the mean is a descriptive normalization afterward.