Algorithm Analysis (CSC 301 2015F) : EBoards

CSC301.01 2015F, Class 37: String Matching Basics


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit

Academic

Peer

Questions

Do we need to write working code for the exam?

Pseudocode is fine. But working code is also fine, provided it's not in ML or a variant thereof.

Do we need to write a program to make the Huffman tree?

No. Construct it by hand. (If you want to write a program, that's fine, but it will be faster to construct by hand.)

When is the final?

2 p.m., Tuesday of Finals week (15th, I think). In-class. One sheet of notes.

Variants of string matching

String matching: Given a target string and a pattern string, find where the pattern string appears in the target string.

Variation one: Do we match exactly or approximately?

Variation two: Given a set of patterns, where does each pattern occur?

Variation three: What is the first occurrence vs. what is any occurrence vs. What are all occurrences?

Approximate string matching, revisited

How would you change the dynamic programming approximate string matching algorithm to find the first matching substring that requires no more than 3 edits?

E.g., If we had a target string of "alphabet" and a pattern of "habit", we can match at position 3 with two edits (one insertion of i, one deletion of e, or vice versa) or with one edit if we allow replacement (replace e with i).

Solution: Use the dynamic programming approximate string matching algorithm, but it costs 0 to delete at the front of the string.

Multiple string matching

Given k strings of length m, find all occurrences of each of the strings in the target, which is of length n.

Analyze. Here's a really bad input

target: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad patterns aaaaaaaaaaaaaaaaaab aaaaaaaaaaaaaaaaaac aaaaaaaaaaaaaaaaaad aaaaaaaaaaaaaaaaaae aaaaaaaaaaaaaaaaaaf

Hint: We studied this once before. DON'T USE DYNAMIC PROGRAMMING.

An obvious solution

for i = 0; i < (n - m)
  for j = 0, j < k; j++
    if (pattern[j] == substring(str, i, m))
      output "pattern[j] matches at position i"

Analysis?

Substring matching