πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

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}

String Matching with Finite Automata

Solution:

q0 is the initial state.

String Matching with Finite Automata

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>