SUBSTRING SEARCH STUDY GUIDE


Terminology and Basics

KMP Boyer-Moore Rabin Karp

Recommended Problems

C level

  1. Fall 2012, #10 (Boyer-Moore)
  2. (a) Given the following KMP DFA, give the string that this DFA searches for
    j 0 1 2 3 4 5 6
    A 1 1 3 1 5 1 5
    B 0 2 0 4 0 6 7
    (b) Below is a partially-completed KMP DFA for a string sof length 6 over the alphabet {a, B}. State 6 is the accept state. Fill in the missing spots in the table.
    j 0 1 2 3 4 5
    pat.charAt(j)
    A 1 1
    B 3 3
    (c) Given each of the following strings as input, what state would the DFA in (b) end in?
    BABAA
    ABABABA
    BABABABA
    BBAABBABAB Answers

B level

  1. (KMP) Below is a partially-completed Knuth-Morris-Pratt DFA for a string s of length 11 over the alphabet { A , B }. Reconstruct the DFA and s in the space below.
          0 1 2 3 4 5 6 7 8 9 10
        A 0 0              10 11
        B       5   2          4
        s                   A
    
    Answers
  2. Spring 2012 Final, #7 (KMP)
  3. Fall 2012, #9 (KMP)
  4. Give an example of when you might want to use KMP? Boyer Moore? Rabin Karp?

A level

  1. For each algorithm (the version discussed in lecture and the textbook), give the worst-case order of growth in terms of M and N.
    ------ brute-force substring search for a query string of size M in a text string of size N
    ------ Knuth-Morris Pratt substring search for a query string of size M in a text string of size N
    ------ Boyer-Moore (with only mismatch heuristic) substring search for a query string of size M in a text string of size N
    ------ Monte Carlo version of Rabin-Karp substring search (that checks only for a hash match) for a query string of size M in a text string of size N
    ------ regular-expression pattern matching for a pattern of size M on a text string of size N
    ------ simulating a DFA with M vertices and 2M edges on a text string of size N
    ------ simulating an NFA with M vertices and 3M edges on a text string of size N Answers
  2. Give an example of when you might prefer to use the Monte Carlo version of Rabin Karp over the Las Vegas version.
  3. Textbook: 5.3.22
  4. Textbook: 5.3.26