You are on page 1of 31

AUTOMATA THEORY

Chapter 02

FINITE AUTOMATA
Deterministic Finite Automata

 A Deterministic Finite Automaton (DFA) is a


5-tuple (Q, , , q0, F) where

Q is a finite set of States

 is an Alphabet, finite set of input symbol

: Q ×  → Q is a Transition Function
(q, a)=p where q= present state
p=next state and a=input
 q0  Q is the Initial State

F  Q is a set of Accepting States (or Final
States) will be denoted by Double Loops.
Notations for DFA

 There are two preferred notations for


describing automata:

1. A Transition Diagram
2. A Transition Table
TRANSITION DIAGRAM

a) For each state in Q there is a node.


b) (q, a)=p arc from node q to p and labeled a.
c) There is an arrow into start state q0, labeled
start.
d) Nodes corresponding to accepting states are
marked by a double circle.
Example

 Draw the Transition Diagram for the DFA


accepting all string with a substring 01.

1 0 0,1

Start 0 1
q0 q1 q2

A=({q0,q1,q2},{0,1},  ,q0,{q2})

Check with the string 01,0111,110101,11101101


TRANSITION TABLE

 A transition table is a conventional, tabular


representation of a function like  that takes two
arguments and return a value.

The rows of the table correspond to the states


and return the columns correspond to the inputs.

The start state is marked with an arrow and accepting


states are marked with a star.
Example with Transition Table

1 0 0,1

Start 0 1
q0 q1 q2

 (q0,0)=q1
 (q0,1)=q0 0 1
 (q1,0)=q1 q0 q1 q0
 (q1,1)=q2
 (q2,0)=q2
q1 q1 q2
 (q2,1)=q2 *q2 q2 q2
TRY THIS

 Substring 011
 Substring end with 01
How a DFA Process String

The language of the DFA is the set of all strings that the DFA
accepts. Suppose a1a2….an is a sequence of input symbols. We
start out with the DFA in its start state q0. We consult the

transition function  say d(q0,a1)=q1 to find the state that the


DFA A enters after processing the first input symbol a1. We

process the next input symbol a2, by evaluating (q1,a2). Let us


suppose this state is q2. we continue this manner, finding

states q3,q4…qn such that (qi-1, ai)=qi for each i. if qn is a


member of F, then the input a1,a2…an is accepted, and if not
then it is rejected.
Extended Transition Formula

 An Extended Transition Function that


describes what happen when we start in any
state and follow any sequence of inputs.

 Transition Function
^
 Extended Transition Function
Extended Transition Formula
^
  takes a state p and a string w, and returns a
state q.
^
1. (q, €)=q
If are in state q and read no. of inputs then we
are still in q.
2. (q,w)= ((q,x),a)
^ ^

w xa
a last symbol
w string
x string consisting of all but the last symbol
Example with Transition Table

1 0 0,1

Start 0 1
q0 q1 q2
^
 (q0, €)=q0
 w= 11011 ^ ^
 x= 1101  (q0,1)= ((q0, €),1) = (q0,1)=q0
^ ^
 a= 1  (q0,11)= ((q0, 1),1)= (q0,1)=q0
^ ^
 (q0,110)=((q0,11),0)= (q0,0)=q1
^ ^
 (q0,1101)=((q0,110),1)=(q1,1)=q2
^ ^
 (q0,11011)=((q0,1101),1)=(q2,1)=q2
The Language of a DFA

 The Language of a DFA, A=(Q, S, , q0, F) is


defined by,

^
L(A)={w| (q0,w) is in F}

That is, the language of A is the set of strings w


that take the start state q0 to one of the accepting
states. If L is L(A) for some DFA, then we say L is
a regular language.
Example

 Let us design a DFA to accept the language

L={w | w has both an even number of 0’s


and even number of 1’s}
1
Start
q 1 q
0 1
0 1 0
0
*q0 q2 q1
0
q1 q3 q0
0
q2 q0 q3 q
1
q
2 3
q3 q3 q1
1
 Extended transition function of the
previous example with the following input

 w = 110101
Nondeterministic Finite Automata

 Like the DFA, an NFA has a finite set of states. A


finite set of input symbols, one start state and a
set of accepting states. It also has a transition
function 

 For the NFA,  is a function that takes a state and


input symbol as arguments but returns a set of
zero, one or more states.

 A Nondeterministic Finite Automaton (NFA) is a 5-


tuple (Q, , , q0, F)
Design an NFA

 An NFA accepting all strings that end in 01

0,1

Start 0 1
q0 q1 q2

Fig: Transition Diagram

Read Details from page -56


How an NFA Process Input Sequence 00101

 An NFA accepting all strings that end in 01


0,1

0 1
q0 q1 q2
Start

Fig: Transition Diagram

q0 q0 q0 q0 q0 q0

q1 q1 q1
(Stuck)
q2 q2
(Stuck) (Accepted)
1 0 1
0 0
Design an NFA

 An NFA accepting all strings that end in 01


0,1

Start 0 1
q0 q1 q2

Fig: Transition Diagram

The NFA can be specified formally as


0 1
({q0,q1,q2},{0,1},  ,q0,{q2})
q0 {q0,q1} {q0}
q1 Ø {q2}
*q2 Ø Ø
Fig: Transition Table
Extended Transition Function

 Basis:
^
  (q0, €) = {q}
 Induction:
 Suppose w=xa
^
  (q ,x)= {p1,p2,p3………pn}
k

 Let U  (p ,a)= {r1,r2,r3,…………rm}


i=1 i

^
 Then  (q ,w)= {r1,r2,r3………rm}
^ Processing of input 00101 by the NFA

0,1

Start 0 1
q0 q1 q2

 ^ (q0, €) = {q0}
^
  (q0,0)=  (q0,0)= {q0,q1}
^
  (q0,00)=  (q0,0) U  (q1, 0)= {q0,q1} U Ø ={q0,q1}
^
  (q0,001)=q0 U  (q1,1)= q} U {q2} ={q0,q2}
^
  (q0,0010)= (q0,0) U  (q2,0) = {q0,q1} U Ø = {q0,q1}
^
  (q0,00101)=(q1,1) U (q0,1)={q0} U {q2}={q0,q2}
Accepted
The language of NFA

 An NFA accepts a string w if it is possible to


make any sequence of choice of next state,
while reading the characters of w, and go
from start state to any accepting states

 If A= (Q, , , q0, F) is an NFA, then


^
 L(A)={w| (q0,w)∩F ≠Ø}
 That is L(A) is the set of strings w in  such
^
that (q0,w) contains at least one accepting
state.
Equivalence of DFA and NFA

 There are many language for which an NFA is easier


than a DFA. Every language that can be describe by
some NFA can also be described by some DFA.

n
 In the worst case the smallest DFA can have 2 states
while the smallest NFA for the same language has n

states.
…..

0,1

Start 0 1
q0 q1 q2

0 1
Ø Ø Ø
{q0} {q0,q1} {q0}
{q1} Ø {q2}
*{q2} Ø Ø
{q0,q1} {q0,q1} {q0,q2}
{q0,q2} {q0,q1} {q0}
{q1,q2} Ø {q2}
{q0,q1,q2} {q0,q1} {q0,q2}
0,1

Start 0 1
q0 q1 q2

0 1
A Ø Ø Ø
B {q0} {q0,q1} {q0}
C {q1} Ø {q2}
*D *{q2} Ø Ø
E {q0,q1} {q0,q1} {q0,q2}
*F {q0,q2} {q0,q1} {q0}
*G {q1,q2} Ø {q2}
*H {q0,q1} {q0,q2}
{q0,q1,q2}
0,1

Start 0 1
q0 q1 q2

0 1 0 1
A Ø Ø Ø A A A
B {q0} {q0,q1} {q0} B E B
C {q1} Ø {q2} C A D
*D *{q2} Ø Ø *D A A
E {q0,q1} {q0,q1} {q0,q2} E E F
*F {q0,q1} {q0} *F E B
{q0,q2}
*G Ø *G A D
{q1,q2} {q2}
*H {q0,q1} *H E F
{q0,q1,q2} {q0,q2}
 From the 8 states in fig starting in the start state
B, we can only reach states B,E and F. The other
five states are inaccessible from the start state.

 The DFA constructed from the fig as…

1 0

Start 0 1
B E F

0
1
1 0

Start 0 1
{q0} {q0,q1} {q0,q2}

0
1
 Theorem 2.11,2.12 (Self)

 Exercise 2.3.1,2.3.2,2.3.3 (Self)

 2.2.3,2.2.4,2.2.5,2.2.6,2.2.10,2.2.11(Self)
Thank You

You might also like