1 / 11

DFA Construccion para KMP

DFA Construccion para KMP. Reference: Chapter 19, Algorithms in C, 2 nd Edition, Robert Sedgewick. DFA Construction for KMP. Search Pattern. j. pattern[1..j]. X. next. a. a. b. a. a. a. b. b. a. b. 0. DFA Construction for KMP. Search Pattern. j. pattern[1..j]. X. next. a.

Télécharger la présentation

DFA Construccion para KMP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DFA Construccion para KMP Reference: Chapter 19, Algorithms in C, 2nd Edition, Robert Sedgewick.

  2. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b a b 0

  3. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 0 a 1 b 0 b a 0 1

  4. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 0 1 a 1 2 b 0 0 b a a 0 1 2 b

  5. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 2 a b 0 2 0 1 2 a 1 2 2 b 0 0 3 a b a a b 0 1 3 2 b

  6. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 2 a b 0 2 0 1 2 3 3 a b a 1 0 a 1 2 2 4 b 0 0 3 0 a b a a a b 0 1 3 4 2 b b

  7. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 2 a b 0 2 0 1 2 3 4 3 a b a 1 0 a 1 2 2 4 5 4 a b a a 2 0 b 0 0 3 0 0 b a b a a a a b 0 1 3 4 2 5 b b

  8. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 2 a b 0 2 0 1 2 3 4 5 3 a b a 1 0 a 1 2 2 4 5 6 4 a b a a 2 0 b 0 0 3 0 0 3 5 a b a a a 2 3 b a b a a a a b a 0 1 3 4 2 5 6 b b b

  9. DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 2 a b 0 2 0 1 2 3 4 5 6 3 a b a 1 0 a 1 2 2 4 5 6 2 4 a b a a 2 0 b 0 0 3 0 0 3 7 5 a b a a a 2 3 6 a b a a a b 3 2 b a b a a a a b b a 0 1 3 4 7 2 5 6 b b b a

  10. b a a b a a a a b b a b 0 1 3 4 7 2 5 6 8 b b b a DFA Construction for KMP Search Pattern j pattern[1..j] X next a a b a a a b b 0 0 0 1 a 1 0 2 a b 0 2 0 1 2 3 4 5 6 7 3 a b a 1 0 a 1 2 2 4 5 6 2 4 4 a b a a 2 0 b 0 0 3 0 0 3 7 8 5 a b a a a 2 3 6 a b a a a b 3 2 7 a b a a a b b 0 4

  11. DFA Construction for KMP: Implementation • Build DFA for KMP. • Takes O(M) time. • Requires O(M) extra space to store next[] table. int X =0; int[] next =newint[M]; for(int j =1; j < M; j++){ if(p.charAt(X)== p.charAt(j)){ // char match next[j]= next[X]; X = X +1; } else{ // char mismatch next[j]= X +1; X = next[X]; } } DFA Construction for KMP (assumes binary alphabet)

More Related