You are on page 1of 13

String Matching

using
Finite state automaton
String Matching

Whenever you use a search engine, or a


“find” function like sed or grep, you are
utilizing a string matching program. Many
of these programs create finite automata in
order to effectively search for your string.
Finite Automata
Finite Automaton Review

• If M reads input character a when in state q, then it


changes to state δ(q, a).
• If its currents state q is in A, then M is said to accept the
string read so far.
• M induces a function ϕ: Σ* → Q, called the final-state
function, such that ϕ(w) is the state of M after reading the
string w. ϕ can be defined recursively as follows:
ϕ(ε) = q0
ϕ(wa) = δ(ϕ(w), a)
• Therefore, M accepts w if and only if ϕ(w) ∈ A.
How it works
A finite automaton accepts
strings in a specific language. It
begins in state q0 and reads
characters one at a time from
the input string. It makes
transitions () based on these
characters, and if when it
reaches the end of the tape it is
in one of the accept states, that
string is accepted by the
language.
The Suffix Function

In order to properly
search for the string, the
program must define a
suffix function ()
which checks to see
how much of what it is
reading matches the
search string at any
given moment.
Example: nano
String-Matching Automata

You might also like