DTWv_{1}, v_{2} {  //where the vectors v_{1}=(a_{1},…,a_{n}), v_{2}=(b_{1},…,b_{m}) are the time series with n and m  time points  Let a two dimensional data matrix S be the store of similarity measures  such that S0,…,n, 0,…,m, and i, j, are loop index, cost is an integer.  // initialize the data matrix  S0, 0 0  FOR i 1 to m DO LOOP  S0, i ∞  END  FOR i 1 to n DO LOOP  Si, 0 ∞  END  // Using pairwise method, incrementally fill in the similarity matrix  with the differences of the two time series  FOR i 1 to n DO LOOP  FOR j 1 to m DO LOOP  // function to measure the distance between the two points  cost dv_{1}i, v_{2}j  S[i, j] cost + MINSi1, j, increment  Si, j−1, decrement  Si1, j−1 match  END  END  Return Sn, m 
}

