Unformatted text preview: Plenty of possible solutions, all rather straightforward implementation of the algorithm presented in class. 2.[20] a.[5] Compute the failure function f for pat = abbababaaabab 1 2 3 4 5 6 7 8 9 10 11 12 13 a b b a b a b a a a b a b f(i) 0 0 0 1 2 1 2 1 1 1 2 1 2 g(i) 0 1 1 1 2 3 2 3 2 2 2 3 2 b.[15] Suppose that x = abaababaababbababaaababaabaababb and we want to know if text x contains pattern pat. How many character comparisons are required by the straightforward algorithm? How many character comparisons are required by procedure the KMP algorithm? Using straightforward algorithm a b a A b a b a a b a b b a b a b a a a b a b a a b a b b # of comparisons pass1 a b b 3 pass2 a 1 pass3 a B 2 pass4 A b b 3 pass5 a 1 pass6 a b b 3 pass7 a 1 pass8 a b 2 pass9 a b b 3 pass10 a 1 pass11 a b b a b a b a a a b a b 13 Total 33...
View
Full Document
 Spring '03
 janicki
 SE2C03. Sample solutions, Implement RatInMaze algorithm, aB pass4 Abb, straightforward algorithm

Click to edit the document details