Õptimal Dynamic Time Warping on Run-Length Encoded Strings

Authors Itai Boneh, Shay Golan , Shay Mozes , Oren Weimann

Thumbnail PDF


  • Filesize: 0.79 MB
  • 17 pages

Document Identifiers

Author Details

Itai Boneh
  • Reichman University, Herzliya, Israel
  • University of Haifa, Israel
Shay Golan
  • Reichman University, Herzliya, Israel
  • University of Haifa, Israel
Shay Mozes
  • Reichman University, Herzliya, Israel
Oren Weimann
  • University of Haifa, Israel

Cite AsGet BibTex

Itai Boneh, Shay Golan, Shay Mozes, and Oren Weimann. Õptimal Dynamic Time Warping on Run-Length Encoded Strings. In 51st International Colloquium on Automata, Languages, and Programming (ICALP 2024). Leibniz International Proceedings in Informatics (LIPIcs), Volume 297, pp. 30:1-30:17, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2024)


Dynamic Time Warping (DTW) distance is the optimal cost of matching two strings when extending runs of letters is for free. Therefore, it is natural to measure the time complexity of DTW in terms of the number of runs n (rather than the string lengths N). In this paper, we give an Õ(n²) time algorithm for computing the DTW distance. This matches (up to log factors) the known (conditional) lower bound, and should be compared with the previous fastest O(n³) time exact algorithm and the Õ(n²) time approximation algorithm. Our method also immediately implies an Õ(nk) time algorithm when the distance is bounded by k. This should be compared with the previous fastest O(n²k) and O(Nk) time exact algorithms and the Õ(nk) time approximation algorithm.

Subject Classification

ACM Subject Classification
  • Theory of computation → Pattern matching
  • Theory of computation → Shortest paths
  • Dynamic time warping
  • Fréchet distance
  • edit distance
  • run-length encoding


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Segment tree beats. URL: https://codeforces.com/blog/entry/57319.
  2. John Aach and George M. Church. Aligning gene expression time series with time warping algorithms. Bioinformatics, 17(6):495-508, 2001. Google Scholar
  3. Amir Abboud, Arturs Backurs, and Virginia Vassilevska Williams. Tight hardness results for LCS and other sequence similarity measures. In 56th FOCS, pages 59-78, 2015. Google Scholar
  4. Pankaj K. Agarwal, Kyle Fox, Jiangwei Pan, and Rex Ying. Approximating dynamic time warping and edit distance for a pair of point sequences. In 32nd SoCG, pages 14-18, 2016. Google Scholar
  5. Saeed Reza Aghabozorgi, Ali Seyed Shirkhorshidi, and Ying Wah Teh. Time-series clustering - A decade review. Inf. Syst., 53:16-38, 2015. Google Scholar
  6. Alberto Apostolico, Gad M. Landau, and Steven Skiena. Matching for run-length encoded strings. Journal of Complexity, 15(1):4-16, 1999. Google Scholar
  7. 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. Google Scholar
  8. Anthony J. Bagnall, Jason Lines, Aaron Bostrom, James Large, and Eamonn J. Keogh. The great time series classification bake off: a review and experimental evaluation of recent algorithmic advances. Data Min. Knowl. Discov., 31(3):606-660, 2017. Google Scholar
  9. Itai Boneh, Shay Golan, Shay Mozes, and Oren Weimann. Near-optimal dynamic time warping on run-length encoded strings, 2023. URL: https://arxiv.org/abs/2302.06252.
  10. Karl Bringmann and Marvin Künnemann. Quadratic conditional lower bounds for string problems and dynamic time warping. In 56th FOCS, pages 79-97. IEEE, 2015. Google Scholar
  11. Horst Bunke and János Csirik. Edit distance of run-length coded strings. In 1992 ACM/SIGAPP Symposium on Applied computing: Technological challenges of the 1990’s, pages 137-143, 1992. Google Scholar
  12. 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. Google Scholar
  13. Raphaël Clifford, Pawel Gawrychowski, Tomasz Kociumaka, Daniel P. Martin, and Przemyslaw Uznanski. RLE edit distance in near optimal time. In 44th MFCS, pages 66:1-66:13, 2019. Google Scholar
  14. Debarati Das, Jacob Gilbert, MohammadTaghi Hajiaghayi, Tomasz Kociumaka, and Barna Saha. Weighted edit distance computation: Strings, trees, and dyck. In 55th STOC, pages 377-390, 2023. Google Scholar
  15. Vincent Froese, Brijnesh J. Jain, Maciej Rymar, and Mathias Weller. Fast exact dynamic time warping on run-length encoded time series. Algorithmica, 85(2):492-508, 2022. Google Scholar
  16. Pawel Gawrychowski and Yanir Edri. private communication, 2016. Google Scholar
  17. Omer Gold and Micha Sharir. Dynamic time warping and geometric edit distance: Breaking the quadratic barrier. In 44th ICALP, volume 80, pages 25:1-25:14, 2017. Google Scholar
  18. Garance Gourdel, Anne Driemel, Pierre Peterlongo, and Tatiana Starikovskaya. Pattern matching under DTW distance. In 29th SPIRE, pages 315-330, 2022. Google Scholar
  19. Guan-Shieng Huang, Jia Jie Liu, and Yue-Li Wang. Sequence alignment algorithms for run-length-encoded strings. In 14th COCOON, volume 5092, pages 319-330, 2008. Google Scholar
  20. Youngha Hwang and Saul B. Gelfand. Fast sparse dynamic time warping. In 26th ICPR, pages 3872-3877, 2022. Google Scholar
  21. Philip N. Klein and Shay Mozes. Optimization algorithms for planar graphs. http://planarity.org. Book draft.
  22. William Kuszmaul. Dynamic time warping in strongly subquadratic time: Algorithms for the low-distance regime and approximate evaluation. In Christel Baier, Ioannis Chatzigiannakis, Paola Flocchini, and Stefano Leonardi, editors, 46th ICALP, volume 132, pages 80:1-80:15, 2019. Google Scholar
  23. William Kuszmaul. Binary dynamic time warping in linear time, 2021. arXiv preprint. Google Scholar
  24. Gad M. Landau and Uzi Vishkin. Fast string matching with k differences. J. Comput. Syst. Sci., 37(1):63-78, 1988. Google Scholar
  25. T. Warren Liao. Clustering of time series data - a survey. Pattern Recognit, 38(11):1857-1874, 2005. Google Scholar
  26. Jia Jie Liu, Guan-Shieng Huang, Yue-Li Wang, and Richard C. T. Lee. Edit distance for a run-length-encoded string and an uncompressed string. Information Processing Letters, 105(1):12-16, 2007. Google Scholar
  27. Alexander De Luca, Alina Hang, Frederik Brudy, Christian Lindner, and Heinrich Hussmann. Touch me once and i know it’s you!: implicit authentication based on touch screen patterns. In SIGCHI Conference on Human Factors in Computing Systems, pages 987-996. ACM, 2012. Google Scholar
  28. Veli Mäkinen, Gonzalo Navarro, and Esko Ukkonen. Approximate matching of run-length compressed strings. Algorithmica, 35(4):347-369, 2003. Google Scholar
  29. J. Mitchell. A geometric shortest path problem, with application to computing a longest common subsequence in run-length encoded strings. Tech-nical Report, Department of Applied Mathemat-ics, SUNY StonyBrook, NY, 1997. Google Scholar
  30. Lindasalwa Muda, Mumtaj Begam, and Irraivan Elamvazuthi. Voice recognition algorithms using mel frequency cepstral coefficient (MFCC) and dynamic time warping (DTW) techniques. arXiv preprint, 2010. Google Scholar
  31. Abdullah Mueen, Nikan Chavoshi, Noor Abu-El-Rub, Hossein Hamooni, and Amanda J. Minnich. Awarp: Fast warping distance for sparse time series. In 16th ICDM, pages 350-359, 2016. Google Scholar
  32. Abdullah Mueen, Nikan Chavoshi, Noor Abu-El-Rub, Hossein Hamooni, Amanda J. Minnich, and Jonathan MacCarthy. Speeding up dynamic time warping distance for sparse time series data. Knowl. Inf. Syst., 54(1):237-263, 2018. Google Scholar
  33. Mario E. Munich and Pietro Perona. Continuous dynamic time warping for translation-invariant curve alignment with applications to signature verification. In 7th ICCV, pages 108-115, 1999. Google Scholar
  34. Eugene W. Myers. An O(ND) difference algorithm and its variations. Algorithmica, 1(2):251-266, 1986. Google Scholar
  35. Saul B. Needleman and Christian D. Wunsch. A general method applicable to the search for similarities in the amino acid sequence of two proteins. Journal of molecular biology, 48(3):443-453, 1970. Google Scholar
  36. Yoshifumi Sakai and Shunsuke Inenaga. A reduction of the dynamic time warping distance to the longest increasing subsequence length. In 31st ISAAC, pages 6:1-6:16, 2020. Google Scholar
  37. Yoshifumi Sakai and Shunsuke Inenaga. A faster reduction of the dynamic time warping distance to the longest increasing subsequence length. Algorithmica, 84(9):2581-2596, 2022. Google Scholar
  38. Nathan Schaar, Vincent Froese, and Rolf Niedermeier. Faster binary mean computation under dynamic time warping. In 31st CPM, pages 28:1-28:13, 2020. Google Scholar
  39. Taras K. Vintsyuk. Speech discrimination by dynamic programming. Cybernetics, 4(1):52-57, 1968. Google Scholar
  40. Xiaoyue Wang, Abdullah Mueen, Hui Ding, Goce Trajcevski, Peter Scheuermann, and Eamonn J. Keogh. Experimental comparison of representation methods and distance measures for time series data. Data Min. Knowl. Discov., 26(2):275-309, 2013. Google Scholar
  41. Zoe Xi and William Kuszmaul. Approximating dynamic time warping distance between run-length encoded strings. In 30th ESA, pages 90:1-90:19, 2022. Google Scholar
  42. Rex Ying, Jiangwei Pan, Kyle Fox, and Pankaj K. Agarwal. A simple efficient approximation algorithm for dynamic time warping. In 24th ACM SIGSPATIAL, pages 21:1-21:10, 2016. Google Scholar
  43. Yunyue Zhu and Dennis Shasha. Warping indexes with envelope transforms for query by humming. In 22nd ACM SIGMOD, pages 181-192, 2003. Google Scholar