MCDMDecision-makingTime-series distanceMath steps

Dynamic Time Warping

Also known as: DTW, dynamic programming time warping, elastic distance

OriginatorHideki Sakoe and Seibi ChibaYear1978Sources2Related methods3

Dynamic Time Warping is a distance metric for comparing time series or sequential data that may vary in length or speed. Introduced by Hideki Sakoe and Seibi Chiba in 1978 for speech recognition, DTW measures the minimal cumulative distance needed to align two sequences using dynamic programming. Unlike fixed-distance metrics, DTW allows flexible time warping, making it ideal for sequences that are similar in shape but offset or scaled differently in time.

Key highlights

  • Handles sequences of different lengths natively
  • Robust to time warping and speed variations; identifies shape similarity
  • Captures intuitive similarity: sequences with same shape but different timing appear similar
  • Well-established in time-series clustering and classification

Intuition

This section is available to Pro members. Upgrade to Pro

How it works

This section is available to Pro members. Upgrade to Pro

When to use it

DTW is ideal for comparing time series of different lengths, comparing sequences with similar patterns but different speeds (speech, motion, sensor data), and any domain where flexible temporal alignment matters. Use it when you care about shape similarity rather than point-by-point temporal alignment. It is computationally more expensive than Euclidean distance, so consider faster variants (FastDTW, LB-DTW) for large datasets.

Strengths & limitations

Strengths
  • Handles sequences of different lengths natively
  • Robust to time warping and speed variations; identifies shape similarity
  • Captures intuitive similarity: sequences with same shape but different timing appear similar
  • Well-established in time-series clustering and classification
Limitations
  • Computationally expensive: O(n*m) time and space for sequences of length n and m
  • No triangle inequality; not a true metric in the mathematical sense
  • Sensitive to outliers and noise in the time series
  • Requires careful parameter tuning (window constraints, normalization) for best results

Common pitfalls

This section is available to Pro members. Upgrade to Pro

Applications

This section is available to Pro members. Upgrade to Pro

Frequently asked

Why is DTW better than Euclidean distance for time series?

Euclidean distance compares points at the same time index, penalizing time shifts. DTW allows flexible alignment, finding the best time-matched path. If sequences have the same shape but different timing, DTW recognizes similarity while Euclidean distance treats them as dissimilar.

Is DTW symmetric?

Yes, DTW(A,B) = DTW(B,A) in the standard definition. However, the alignment path may differ due to the direction of backtracking. DTW is symmetric but not a true metric because it does not satisfy the triangle inequality.

How do I handle sequences of very different lengths?

DTW handles length differences naturally. However, very large length differences can lead to trivial alignments (many-to-one mappings). Constrain the warping window (Sakoe-Chiba band) to enforce local alignment and prevent excessive distortion.

What is FastDTW and when should I use it?

FastDTW is a faster approximation of DTW with O(n*m) time complexity but lower space overhead and practical speedup through coarse-to-fine refinement. Use FastDTW when comparing many sequences or working with long sequences where standard DTW is too slow.

Sources

  1. 1.
    Sakoe, H., & Chiba, S. (1978). Dynamic programming algorithm optimization for spoken word recognition. IEEE Transactions on Acoustics, Speech, and Signal Processing, 26(1), 43-49.
  2. 2.
    Salvador, S., & Chan, P. (2007). FastDTW: Toward accurate dynamic time warping in linear time and space. KDD Explorations, 5(1), 70-86.

You have read it. What now?

Cite this page

ScholarGate. (2026, June 3). Dynamic Time Warping. ScholarGate. https://scholargate.app/decision-making/dynamic-time-warping

Dynamic Time Warping — Dynamic Time Warping Distance