You are viewing a single comment's thread. Return to all comments →
Scala solution works with prefix function as ArrayBuffer.
Description of pseudocode for the table-building algorithm in the Wikipedia link is not correct.
Correct algorithm can be found here https://cp-algorithms.com/string/prefix-function.html#implementation
vector<int> prefix_function(string s) { int n = (int)s.length(); vector<int> pi(n); for (int i = 1; i < n; i++) { int j = pi[i-1]; while (j > 0 && s[i] != s[j]) j = pi[j-1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; }
Seems like cookies are disabled on this browser, please enable them to open this website
Substring Searching
You are viewing a single comment's thread. Return to all comments →
Scala solution works with prefix function as ArrayBuffer.
Description of pseudocode for the table-building algorithm in the Wikipedia link is not correct.
Correct algorithm can be found here https://cp-algorithms.com/string/prefix-function.html#implementation