In line "beg = 0, end = qlen", I think "end" should be initialized as "end=w+1".
Also, "end=min(end,i+w+1)" should be replaced with "end=max(end,i+w+1)".
For ex- While aligning (CATT,ACT), using w=1, if the original code is used, then as "end=min(end,i+w+1)" will always keep "end=w+1=1" across all iterations i. Thus, the end of the band is never extended.
The above corrections on the other hand, fill the cells that are required for aligning the 2 strings.
In line "beg = 0, end = qlen", I think "end" should be initialized as "end=w+1".
Also, "end=min(end,i+w+1)" should be replaced with "end=max(end,i+w+1)".
For ex- While aligning (CATT,ACT), using w=1, if the original code is used, then as "end=min(end,i+w+1)" will always keep "end=w+1=1" across all iterations i. Thus, the end of the band is never extended.
The above corrections on the other hand, fill the cells that are required for aligning the 2 strings.