Below is text from Introduction to Algorithms by CLRS. Below is code snippet in string matching using finite state automata. Trnstion function is used to construct state table with pattern to be searched.
Computing the transition function: The following procedure computes the transition function sigma from a given pattern P [1: :m].
COMPUTE-TRANSITION-FUNCTION.
1 m = P:length
2 for q = 0 to m
3 for each character a belongs to alphabetset
4 k = min (m + 1, q + 2)
5 repeat
6 k = k - 1
7 until Pk is suffix Pqa
8 sigma(q, a) = k
9 return sigma
This procedure computes sigma(q, a) in a straightforward manner according to its definition in equation (32.4). The nested loops beginning on lines 2 and 3 consider all states q and all characters a, and lines 4–8 set sigma(q, a) to be the largest k such that Pk is suffix Pqa. The code starts with the largest conceivable value of k, which is min(m, q+1). It then decreases k until Pk is suffix Pqa, which must eventually occur,since P0 is empty string which is a suffix of every string.
My questions on above code
Why author is selecting k as min(m + 1, q+2) at line 4?
In below explantion text author is mentions that "The code starts with the largest conceivable value of k, which is min(m, q+1)." Which is not matching with pseudo code above at line 4?
Request to explain with simple example and steps of psudoe code while answering above questions.