{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# ch11 - 1Pattern matching Application text graphics...

This preview shows pages 1–3. Sign up to view the full content.

1 Pattern matching Application text graphics compilers sub-lists ... P - pattern of length m T - text of length n j - pattern position k - text position Vanilla flavored algorithm best case O(m) worst case O(m*n) -- T = AAAAAAAA... P = AAB Causes backups Count character comparisons as a measure of work. If the pattern and the text can match every time, but in the last character, the worst case would be realized. O(mn). If the pattern is in the first m characters of the text, best case would be realized, O(m). If the first character of the pattern in is not in the text at all, O(n). P: ABABC ABABC ABABC T: ABABABCCA ABABABCCA ABABABCCA

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Consider a FSM - 2 types of nodes Read Stop Let the distinct characters of T and P be 3 , and 2200 = Each state has 2200 arrows out of it, each arrow labeled with one symbol from 3 . After the construction of FSM, the algorithm runs in O(n), no text is ever considered twice. Difficulty is in constructing FSM. The FSM states remember what has been seen so far. Now patterns can be recognized in O(n). Again, the problem is in building the FSM. It is easy to build the successful match links as follows. Enter Knuth-Morris-Pratt (KMP) Also uses a FSM contains success links and failure links only characters are in the nodes, not on the links there is a special read node The KMP algorithm uses success and failure links, characters are in the nodes. The next character is read upon following a success link.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}