Question: Give a justification of why the computeFailKMP method (Code Fragment 13.4) runs in O(m) time on a pattern of length m. 1 private static int[]
![1 private static int[] computeFailKMP(char[ ] pattern) { int m = pattern.length; int[ ] fail = new int[m]; int j = 1; 2](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1544/6/2/8/3255c112865dcea01544610886310.jpg)
1 private static int[] computeFailKMP(char[ ] pattern) { int m = pattern.length; int[ ] fail = new int[m]; int j = 1; 2 // by default, all overlaps are zero 3 4 int k = 0; while (j < m) { if (pattern[i] = faili] = k + 1; j++; k++; } else if (k > 0) k = fail[k-1]: else 5 // compute fail li] during this pass, if nonzero // k +1 characters match thus far pattern[k]) { 10 // k follows a matching prefix 11 12 // no match found starting at j 13 14 j++; } return fail; 15 16 17 }
Step by Step Solution
3.34 Rating (157 Votes )
There are 3 Steps involved in it
The justification is similar to the argument that the number of i... View full answer
Get step-by-step solutions from verified subject matter experts
