16_KMP_PatternMatching1

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

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

CSC 30155 Tuesday 08/11/10 Dr. Daniel Hughes [email protected]

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

View Full Document
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)
Supporting Reading l Optional reading: l Cormen et al., Introduction to Algorithms , MIT Press, 2001, Chapter 32.3 and 32.4.

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

View Full Document
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.
CSC 30155 Building the FSA Transition Function Dr. Daniel Hughes [email protected]

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

View Full Document
Recall our FSA for String Matching:
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

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

View Full Document
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) .
Question 1: 5 minutes l Calculate the worst-case time complexity of COMPUTE-TRANSITION-FUNCTION.

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

View Full Document
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.
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}.

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

View Full Document
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}.
CSC 30155 Knuth-Morris Pratt Pattern Matching Dr. Daniel Hughes [email protected]

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

View Full Document
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
Ask a homework question - tutors are online