Dynamic Time Warping
Dynamic Time Warping Distance · Also known as: DTW, dynamic programming time warping, elastic distance
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.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
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
- 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
- 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
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
- 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. DOI: 10.1109/TASSP.1978.1163055 ↗
- Salvador, S., & Chan, P. (2007). FastDTW: Toward accurate dynamic time warping in linear time and space. KDD Explorations, 5(1), 70-86. link ↗
How to cite this page
ScholarGate. (2026, June 3). Dynamic Time Warping Distance. ScholarGate. https://scholargate.app/en/decision-making/dynamic-time-warping
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- Levenshtein DistanceDecision-making↔ compare