16_KMP_PatternMatching1

16_KMP_PatternMatching1 - Tuesday 08/11/10 Dr. Daniel Hughes

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 30155 Tuesday 08/11/10 Dr. Daniel Hughes [email protected]
Background image of page 1

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

View Full DocumentRight Arrow Icon
The Plan for Today l Review: FSA Transition Function (20 mins) l Introduction to Knuth-Morris-Pratt Pattern Matching (20 mins) l Tutorial Assignment (5 mins)
Background image of page 2
Supporting Reading l Optional reading: l Cormen et al., Introduction to Algorithms , MIT Press, 2001, Chapter 32.3 and 32.4.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Notes l Tomorrow, we will also go over the second final year project assignment (design). l I will also hand out volunteer information sheets for the upcoming conference. l My apologies: I have been very busy this week, so the materials are not yet on ICE, however, I will fix this ASAP.
Background image of page 4
CSC 30155 Building the FSA Transition Function Dr. Daniel Hughes [email protected]
Background image of page 5

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

View Full DocumentRight Arrow Icon
Recall our FSA for String Matching:
Background image of page 6
Recall our FSA for String Matching: l When give the transition function δ , our FSA algorithm demonstrates O(n) efficiency, but this is cheating! l Calculation of δ has a a higher time complexity. l Lets take a look at an algorithm to compute the transition function
Background image of page 7

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

View Full DocumentRight Arrow Icon
COMPUTE-TRANSITION-FUNCTION for FSA Matching: Pseudocode l We declare a data structure that holds one state q per character in P . l For each state and for each character in the alphabet, step backwards through the pattern, marking the current position as k . l We set the current q value for δ (q, x) to be equal to the first instance where P 0-k is a prefix of P 0-q x where q is the last state: l i.e. (q, x) = σ (Pqx) .
Background image of page 8
Question 1: 5 minutes l Calculate the worst-case time complexity of COMPUTE-TRANSITION-FUNCTION.
Background image of page 9

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

View Full DocumentRight Arrow Icon
Question 1: 5 minutes l Calculate the worst-case time complexity of COMPUTE-TRANSITION-FUNCTION. l O(m 3 |A|) because: l The outer loops contribute a factor of m|A|. l The inner loop can run at most m+1 times. l The test on line 6 may require comparison of up to m characters.
Background image of page 10
Question 2: 10 minutes l Construct the finite automaton (the transition function δ ) so that this algorithm can be used to find matches of the pattern P = {a, c, t, t,} using alphabet A = {a, c, g, t}.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Question 3: 5 minutes l Simulate the process of running the automaton you just constructed on T = {t, a, c, t, t, a, c, t}.
Background image of page 12
CSC 30155 Knuth-Morris Pratt Pattern Matching Dr. Daniel Hughes [email protected]
Background image of page 13

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

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/22/2011 for the course CSC 30155 taught by Professor Garyli during the Spring '11 term at University of Liverpool.

Page1 / 34

16_KMP_PatternMatching1 - Tuesday 08/11/10 Dr. Daniel Hughes

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online