We compute $s(j;i,r)$ recursively. First, we initialize $s(j;i,r)=\u221e$ if $j<1$, $i<0$, or $r<0$ with the exception $s(0;0,0)=0$. Then, $s(j;i,r)$ can be obtained by finding the minimum among three casesDisplay Formula
5$s(j;i,r)=min{s(j\u22121;i,r)+dm(j,k),s(j\u22121;i\u22121,r)+du(j),s(j;i,r\u22121)},$
where $k=j\u2212i+r$. When $Xj$ matches $Yk$, the matching cost $dm(j,k)$ is added to $s(j\u22121;i,r)$, which is the first term in Eq. 5. When $Xj$ is an inserted frame, the unmatched cost $du(j)$ is added to $s(j\u22121;i\u22121,r)$. If $Yk$ is a removed frame, $s(j;i,r\u22121)$ remains unchanged. In this way, we compute all $s(j;i,r)$ inductively. Finally, the minimum sum of costs for the whole sequence is given by $minmax{0,lX\u2212lY}\u2a7di\u2a7d\nu Is(lX;i,lY\u2212lX+i)$. While computing the partial costs in Eq. 5, we also record the minimum conditions, which we can trace back to get the matching function in Eq. 3.