The dynamic time warping algorithm provides a notion of distance between two trajectories $s$ and $t$ with points indexed by $s_i$ and $t_j$. The dynamic programming algorithm is only a few lines and the key formula is:
$$D(i+1,j+1)=cost+min\{D(i,j+1),D(i+1,j),D(i,j)\},$$ where $$cost=norm(s_i-t_j).$$
After looping for $i$ and $j$ the last element of the cache matrix $d=D(size(s)+1,size(t)+1)$ provides the dynamic time warping distance. This value should correspond to the optimal trajectory alignment in the sense that the sum of euclidean pairwise distances is minimized. Moreover, valid trajectory alignments should satisfy some simple rules such as monotonicity.
I am not able to see why such a recursive algorithm provides the solution to this minimization problem. Is it trivial? Can someone help me understand this?
Fix index $(i+1, j+1)$. There is a few decisions you can choose:
We want the decision that minimizes the time warping distance. So we take the minimum of all of them, and you get your recurrence.