String Matching with Finite Automata
The string-matching automaton is a very useful tool which is used in string matching algorithm. It examines every character in the text exactly once and reports all the valid shifts in O (n) time. The goal of string matching is to find the location of specific text pattern within the larger body of text (a sentence, a paragraph, a book, etc.)
Finite Automata:
A finite automaton M is a 5-tuple (Q, q0,A,βΞ΄), where
- Q is a finite set of states,
- q0 β Q is the start state,
- A β Q is a notable set of accepting states,
- β is a finite input alphabet,
- Ξ΄ is a function from Q x β into Q called the transition function of M.
The finite automaton starts in state q0 and reads the characters of its input string one at a time. If the automaton is in state q and reads input character a, it moves from state q to state Ξ΄ (q, a). Whenever its current state q is a member of A, the machine M has accepted the string read so far. An input that is not allowed is rejected.
A finite automaton M induces a function β called the called the final-state function, from β* to Q such that β (w) is the state M ends up in after scanning the string w. Thus, M accepts a string w if and only if β (w) β A.
The function f is defined as
β (β)=q0 β (wa) = Ξ΄ ((β (w), a) for w β β*,aβ β)
FINITE- AUTOMATON-MATCHER (T,Ξ΄, m),
1. n β length [T]
2. q β 0
3. for i β 1 to n
4. do q β Ξ΄ (q, T[i])
5. If q =m
6. then sβi-m
7. print "Pattern occurs with shift s" s
The primary loop structure of FINITE- AUTOMATON-MATCHER implies that its running time on a text string of length n is O (n).
Computing the Transition Function: The following procedure computes the transition function Ξ΄ from given pattern P [1......m]
COMPUTE-TRANSITION-FUNCTION (P, β)
1. m β length [P]
2. for q β 0 to m
3. do for each character a β β*
4. do k β min (m+1, q+2)
5. repeat kβk-1
6. Until
7. Ξ΄(q,a)βk
8. Return Ξ΄
Example: Suppose a finite automaton which accepts even number of a's where β = {a, b, c}

Solution:
q0 is the initial state.

Discussion & Queries (<$I18NNumComments$>):
<$CommentPager$>
- <$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>
<$CommentPager$>
<$BlogCommentBody$>
<$BlogCommentDeleteIcon$>