I am having trouble understanding the affine gap penalty in the following example -
Waterman-Smith-Beyer Algorithm:
\begin{align*} D_{0,0} &= 0\\ D_{0,j} &= g(j)\\ D_{i,0} &= g(i)\\ \forall i,j > 0,~ S_{i,j} &= \min \begin{Bmatrix} \min_{1 \leq k \leq j}{(D_{i,j-k} + g(k))}\\ D_{i-1,j-1} + w(a_i,b_j)\\ \min_{1 \leq k \leq j}{(D_{i-k,j} + g(k))}\\ \end{Bmatrix} \end{align*} where $g(k)$ is the gap penalty function and $w$ is the similarity score.
The affine gap penalty here is $g(k) = 1 + k$ and the mismatch score is $1$ and the match score is $0$.
I am not sure where the 3 and 4 come from or the 4 and 5 in cells 1,3 and 2,4. I'm not understanding how the affine gap penalty works here. I understand how the linear gap penalty worked in the Needlemen_Wunsch but not this. Is k the gaps before hand?