You are on page 1of 25

Finite State Automata (FA)

0 1 1 0 0

Finite
Control

• One-way, infinite tape, broken into cells


• Read-only tape head.
• Finite control, i.e., finite number of states, and
• A string is placed on the tape, read head is positioned at the left end.
FA will read the string one symbol at a time until all symbols have been read.
The FA will then either accept or reject the string.
FSA Applications
• Lexical analysis (Compiler) recognition of tokens
• Thermostats (fridge)
• Elevators
• Train Track Switches
• Text editing
• Image compression
• Computer Network
Deterministic Finite State Automata (DFA)
A deterministic finite automaton is a 5-tuple M = (Q, Σ, , q0, F), where
• Q - is a finite set of states
• Σ - is a finite set of input symbols
• q0  Q - is the start state (initial state)
• F  Q - is the set of accept states (final states)
•  : Q  Σ → Q - is the transition function
Q = {q0 , q1 } , Σ = { a, b}

n(Q) = 2 , n(Σ) = 2

A x B = { (x, y) / x  A , y  B } - Cartesian Product of A and B

n(A x B) = n(A) . n(B)

Q x Σ = { (q0, a), (q0, b), (q1, a), (q1, b) }

n(Q x Σ) = n(Q). n(Σ) = 2 . 2 = 4

:QΣ→Q
Examples
M = ( {q0 , q1 , q2 , D } , {a, b} , q0 ,  , {q2} ) a b
q1 D
where (q0 , a) = q1 (q0 , b) = D q0
q1 q2
(q1 , a) = q1 (q1 , b) = q2 q1 D q2

(q2 , a) = D (q2 , b) = q2 q2 D D
(D , a) = Da (D , b) = D D
Transition Table or State Table

q0 a b b
q1 q2
Transition diagram or State diagram
b a
D
a,b
Extended Transition Function
^
*
Extend  to  : Q   Q
a q1 b c
^ q0 q2 q3
1)  ( q,  )  q, q  Q ^ ^
 (q0 , abc)   ( ( q0 , ab), c)
* ^
2) x   , a  , q  Q   ( ( (q0 , a ), b), c)
^
^ ^
  ( ( ( (q0 ,  ), a ), b), c)
 (q, xa)   ( (q, x), a)
  ( ( ( q0 , a ), b), c)
  ( ( q1 , b), c)
  (q2 , c)  q3
Grammar and Automata
L(M) is the of strings accepted by M
^
L ( M )  { x / x   ,  ( q0 , x )  F }
*

L(G) is the of strings generated by G


*
*
L (G )  {w  T / S  w}

M - Automata is an accepting device of the language


G - Grammar is the generating device of the language
Examples
1) a
a,b
n
q0 b a,b
L( M )  {a b / n  0}
q1 q2
Trap state

a,b

2) q1   {a, b}
*
L( M )  
3) a

q0 q1
L( M )  {(ab) n / n  0}
b
b a

a,b
4) a,b   {a, b}
a,b 
q0 q1 L(M )  
5)
a,b
q0 q1

a,b a,b

  {a, b} q2

*
L( M )  {x / x   , | x | 3k , k  0,1,2,...}
DFA
Language accepted by a FSA is called regular set or regular language

Theorem: A language L is called regular if and only if there exists some


deterministic finite accepter M such that
L = L(M)
Non-deterministic Finite Automata (NFA)
A non-deterministic finite automaton is a 5-tuple M = (Q, Σ, , q0, F),
where
• Q - is a finite set of states
• Σ - is a finite set of input symbols
• q0  Q - is the start state (initial state)
• F  Q - is the set of accept states (final states)
•  : Q  Σ → 2Q - is the transition function

(qi , a) = { qi , q j }
Q = {q0 , q1 } , Σ = { a, b}

n(Q) = 2 , n(Σ) = 2

ρ(Q) = 2Q = { {q0} , {q1} , {q0 , q1 }, {ϕ} } - Power set of Q

n(2Q) = 2n(Q) = 22 = 4
 : Q  Σ → 2Q
QΣ 2Q

(q0, a) (q0, a ) = {q0 q1}

(q0, b)
(q1, b ) = { q0}
(q1, a)

(q1, b)

(qi, a ) = {qj , qk} qj


a

qi
a qk
Example - 1
a a
 (q0 , a)  {q1 , q4 }
q1 q2 q3
a  (q1 , a)  {q2 }
q0 a
 (q2 , a)  {q3}
a q4 q5
 (q4 , a )  {q5 }
a  (q5 , a )  {q4 }
3 2n
L( M )  {a }  {a / n  1}
Example - 2

a b a b

a b q0 {q0 , q1} 
q0 q1 q2

q1  {q1 , q2 }

q2  
n m
L( M )  {a b / m, n  1}
NFA to DFA (Procedure)
1. Create a graph GD with vertex {q0 }. Identify this vertex as the initial
vertex.
2. Repeat the following steps until no more edges are missing:
Take any vertex {qi , q j ,...., qk } of GD that as no outgoing edge
for some . Compute  {qi , a ),  {q j , a ),...,  {qk , a ).

If  {qi , a )   {q j , a )  ...   {qk , a )  {ql , qm ,..., qn }


create a vertex for GD labeled {ql , qm ,..., qn }if it does not
already exist. Add to GD an edge from {qi , q j ,...., qk } to
{ql , qm ,..., qn } and labeled it with a .
NFA to DFA (Procedure)
3. Every vertex of GD whose label contains any q f  F is identified as a
final state.

4. If MN accepts  , the vertex {q0 } in GD is also a final state.


Example – 1 q1 a
q2
a q3
a

q0 a
A

a q4 q5

δ(q0 , a) = {q1 a, q4}

q0

δ(q1 , a) U δ(q4 , a) = {q2}U{q5} = {q2 , q5}


a q1,q4
q0
a q1,q4 a
q0 q2,q5

δ(q2 , a) U δ(q5 , a) = {q3}U{q4} = {q3 , q4}


a a a
q0 q1,q4 q2,q5 q3,q4

δ(q3 , a) U δ(q4 , a) = {ϕ}U{q5} = {q5}

a q1,q4 a a a
q0 q2,q5 q3,q4 q5
δ(q5 , a) = {q4}
a a a a a
q0 q1,q4 q2,q5 q3,q4 q5 q4

δ(q4 , a) = {q5}

q0 a q1,q4 a a a a
q2,q5 q3,q4 q5 q4

a
NFA with  moves (-NFA)
A non-deterministic finite automaton with  moves is a 5-tuple
M = (Q, Σ, , q0, F), where
• Q - is a finite set of states
• Σ - is a finite set of input symbols
• q0  Q - is the start state (initial state)
• F  Q - is the set of accept states (final states)
•  : Q  Σ U { } → 2Q - is the transition function
-closure
-closure of a state q is the set of all states reachable from q through
-moves only and including q itself.

-closure(q0) = {q0 , q1 , q2 , q3} ECLOSURE(q0)


-closure(q1) = { q1 , q2 , q3}
a b c d
-closure(q2) = { q2 , q3}
  
-closure(q3) = {q3} q0 q1 q2 q3

L( M )  {a n b m c k d p / m, n, k , p  0}
Q = {q0 , q1 } , Σ = { a, b} , Σ U { } = { a, b, }

n(Q) = 2 , n(Σ U { } ) = 3

Q x (Σ U { } ) = {(q0, ), (q0, a), (q0, b), (q1, ), (q1, a), (q1, b) }

ρ(Q) = 2Q = { {q0} , {q1} , {q0 , q1 }, {ϕ} } - Power set of Q

n(2Q) = 2n(Q) = 22 = 4
 : Q  ( Σ U { })→ 2Q
Q  (ΣU { }) 2Q

(q0 , ) (q0,  ) = {q0 q1}

(q0, b)
(q1, b ) = { q0}
(q1, a)

(q1, b)

(q1 , ))

(qi, ) = {qj , qk} qj


qi
 qk

You might also like