Professional Documents
Culture Documents
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 1
Finite Automaton (FA)
Informally, a state diagram that comprehensively
captures all possible states and transitions that a
machine can take while responding to a stream or
sequence of input symbols
Recognizer for “Regular Languages”
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 2
Deterministic Finite Automata
- Definition
A DFA can be represented by a 5-tuple
(Q, ∑, δ, q0, F) where −
Q is a finite set of states.
∑ is a finite set of symbols called the alphabet.
δ is the transition function where
δ: Q × ∑ → Q
q0 is the initial state from where any input is
processed (q0 ∈ Q).
F is a set of final state/states of Q (F ⊆ Q).
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 3
Graphical Representation of a
DFA: State Diagram
Graphical Representation of a DFA
A DFA is represented by
digraphs called state diagram.
The vertices represent the
states.
The arcs labeled with an input
alphabet show the transitions.
The initial state is denoted by an
empty single incoming arc.
The final state is indicated by
double circles or *.
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 4
Transition Table:
The transition table is basically a tabular
representation of the transition function. It
takes two arguments (a state and a symbol)
and returns a state (the "next state").
Columns correspond to input symbols.
Rows correspond to states.
Entries correspond to the next state.
Present Next Next
The start state is denoted by an arrow
State state for State of with no source.
Input 0 Input 1 The accept state is denoted by a double
circle .
→q0 q1 q2
q1 q0 q2
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
q2
q2 q2 Professor & HOD
Dept of CSE,JNTUHCEM 5
Example #1
Build a DFA for the following language:
L = {w | w is a binary string that contains 01 as a substring}
Steps for building a DFA to recognize L:
∑ = {0,1}
Decide on the states: Q
Designate start state and final state(s)
δ: Decide on the transitions:
“Final” states == same as “accepting states”
Other states == same as “non-accepting states”
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
6
Regular expression: (0+1)*01(0+1)*
1 0 0,1 • ∑ = {0,1}
• start state = q0
start 0 1
q0 q1 q2 • F = {q2}
Accepting • Transition table
state symbols
0 1
q0 q1 q0
states
q1 q1 q2
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE *q2 q2 q2
Professor & HOD
Dept of CSE,JNTUHCEM • * indicate final state 7
Extension of transitions (δ) to
Paths (δ)
δ (q,w) = destination state from state q on input string w
In above example :
δ (q0,1)=qo
δ (q0,0)=q1
δ (q1,0)=q1
δ (q1,1)=q2
δ (q2,0)=q2
δ (q2,1)=q2
Note: if no transition output is :⏀
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 8
Example #2
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and
ends with 0.
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 9
DFA:String acceptance
In Above example
= δ (q0,1110)
= δ(q1,110)
=δ(q1,10)
=δ(q1,0)
=δ(q2, ε) (δ(q, ε)=q)
=q2 (final state) string
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 10
Example #3
Build a DFA for the following language:
L = { w | w is a binary string that has even
number of 1s and even number of 0s}
?
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
11
Non-deterministic Finite
Automata (NFA)
A Non-deterministic Finite Automaton
(NFA)
is of course “non-deterministic”
Implying that the machine can exist in more
than one state at the same time
Transitions could be non-deterministic
1 qj
qi … • Each transition function therefore
1 maps to a set of states
qk
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 12
Non-deterministic Finite
Automata (NFA)
An NFA is also defined by the 5-tuple:
{Q, ∑ , q0,F, δ }
Q ==> a finite set of states
∑ ==> a finite set of input symbols (alphabet)
q0 ==> a start state
F ==> set of accepting states
δ ==> a transition function, which is a mapping
between Q x ∑ ==> 2Q
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 13
How to use an NFA?
Input: a word w in ∑*
Question: Is w acceptable by the NFA?
Steps:
Start at the “start state” q0
For every input symbol in the sequence w do
Determine all possible next states from all current states, given
the current input symbol in w and the transition function
If after all symbols in w are consumed and if at least one of
the current states is a final state then accept w;
Otherwise, reject w.
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
14
Regular expression: (0+1)*01(0+1)*
Then, δ (q0,wa) = S1 U S2 U … U Sk
δ (q1,1)=q2
δ (q2,0)=q2
δ (q2,1)=q2
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 19
Note: Omitting to explicitly show error states is just a matter of design convenience
(one that is generally followed for NFAs), and
i.e., this feature should not be confused with the notion of non-determinism.
→q0 q1 q1
q1 q2 q2
*q2 ε ε
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 22
But, DFAs and NFAs are equivalent in their power to capture langauges !!
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 23
Equivalence of DFA & NFA
Theorem:
A language L is accepted by a DFA if and only if
it is accepted by an NFA.
Proof:
1. If part:
Prove by showing every NFA can be converted to an
equivalent DFA (in the next few slides…)
2. Only-if part is trivial:
Every DFA is a special case of an NFA where each
state has exactly one transition for every input symbol.
Therefore, if L is accepted by a DFA, it is accepted by
a corresponding NFA.
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 24
Proof for the if-part
If-part: A language L is accepted by a DFA if it
is accepted by an NFA
rephrasing…
Given any NFA N, we can construct a DFA D
such that L(N)=L(D)
How to convert an NFA into a DFA?
Observation: In an NFA, each transition maps to a
subset of states
Idea: Represent:
each “subset of NFA_states” a single “DFA_state”
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 25
NFA to DFA by subset construction
Let N = {QN,∑,δN,q0,FN}
Goal: Build D={QD,∑,δD,{q0},FD} s.t.
L(D)=L(N)
Construction:
1. QD= all subsets of QN (i.e., power set)
2. FD=set of subsets S of QN s.t. S∩FN≠Φ
3. δD: for each subset S of QN and for each input symbol
a in ∑:
δD(S,a) = U δN(p,a)
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 26
NFA to DFA construction:
Example
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
27
FA with -Transitions
We can allow explicit -transitions in finite automata
i.e., a transition from one state to another state
introduce non-determinism.
Makes it easier sometimes to construct NFAs
table
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 28
Example of an -NFA
L = {w | w is empty, or if non-empty will end in 01}
0,1
0 1
-closure of a state q,
q0 q1 q2 ECLOSE(q), is the set
of all states (including
start q’0 itself) that can be
reached from q by
δE 0 1
repeatedly making an
*q’0 Ø Ø {q’0,q0}
ECLOSE(q’0) arbitrary number of -
q0 {q0,q1} {q0} {q0} ECLOSE(q0) transitions.
ECLOSE(q1)
q1 Ø {q2} {q1}
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
*q2 Ø Ø {q2} ECLOSE(q2) Professor & HOD
Dept of CSE,JNTUHCEM 29
To simulate any transition:
Step 1) Go to all immediate destination states.
Step 2) From there go to all their -closure states as well.
Example of an -NFA
L = {w | w is empty, or if non-empty will end in 01}
0,1
0 1
Simulate for w=101:
q0 q1 q2
q0’
start q’0
q0’ q0
1 1
δE 0 1 Ø q0
x 0
ECLOSE(q’0)
*q’0 Ø Ø {q’0,q0} q1
q0 {q0,q1} {q0} {q0} ECLOSE(q0) 1
q2
q1 Ø {q2} {q1}
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
*q2 Ø Ø {q2} Professor & HOD 30
Dept of CSE,JNTUHCEM
Equivalency of DFA, NFA, -NFA
Theorem: A language L is accepted by
some -NFA if and only if L is accepted by
some DFA
Implication:
DFA ≡ NFA ≡ -NFA
(all accept Regular Languages)
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
31
Eliminating -transitions
Let E = {QE,∑,δE,q0,FE} be an -NFA
Goal: To build DFA D={QD,∑,δD,{qD},FD} s.t. L(D)=L(E)
Construction:
1. QD= all reachable subsets of QE factoring in -closures
2. qD = ECLOSE(q0)
3. FD=subsets S in QD s.t. S∩FE≠Φ
4. δD: for each subset S of QE and for each input symbol a∑:
Let R= U δE(p,a) // go to destination states
p in s
δD(S,a) = U ECLOSE(r) // from there, take a union
r in R of all their -closures
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 32
Example: -NFA DFA
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
33
Minimization of DFA
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 34
Moore Machine
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
36
Mealy Machine
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 38
Conversion from Mealy machine to Moore Machine
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
39
steps converting Mealy machine to the Moore machine:
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM 41
Conversion from Moore machine to
Mealy Machine
Adobe Acrobat
Document
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Professor & HOD
Dept of CSE,JNTUHCEM
44
Dr.K.Shahu Chatrapati Ph.D,MCSI,MISTE
Summary
Professor & HOD
Dept of CSE,JNTUHCEM
DFA
Definition
NFA
Definition