In every case, we propose a shift of j-k. Negative values occur for case 3, but the other heuristic is always greater than 0, so the max guarantees progress.
Define to be the index of the right-most index of a in
P. If
then
.
Then is the bad-character shift we want.
(j is current offset from s in T, T[s+j] is the current character.)