stevenhalim / cpbook-code

CP4 Free Source Code Project (C++17, Java11, Python3 and OCaml)
2k stars 493 forks source link

Possible error found in CP4 book 2 #99

Open ajadhav opened 2 years ago

ajadhav commented 2 years ago

Hi, I've been looking at the KMP example on pg 335 in Chapter 6 of CP4 book 2. I noticed that in the examples you seem to preprocess a table that is pattern size + 1, so that the kmpSearch can reset correctly once a match is found (j = b[j]) However the kmpPreprocess function seems to only iterate for i < m. Assuming m is the size of the pattern string we won't fully fill out the table, should the preprocessing iterate for i <= m ? Or is m here the size of the pattern+1? Or maybe I am misunderstanding something. Any clarification is appreciated!

Thanks, Anup