Finite Automata and DFA Concepts
Finite Automata and DFA Concepts
1
Syllabus
UNIT-1
Basic Concepts and Automata Theory: Introduction to Theory of
Computation- Automata, Computability and Complexity, Alphabet,
Symbol, String, Formal Languages,
Deterministic Finite Automaton (DFA)- Definition, Representation,
Acceptability of a String and Language,
Non Deterministic Finite Automaton (NFA), Equivalence of DFA and
NFA, NFA with ε-Transition, Equivalence of NFA’s with and without
ε-Transition,
Finite Automata with output- Moore Machine, Mealy Machine,
Equivalence of Moore and Mealy Machine,
Minimization of Finite Automata,
Myhill-Nerode Theorem, Simulation of DFA and NFA
05/02/2025 2
UNIT-1
05/02/2025 3
Finite Automata
4
Introduction to Automata
5
Introduction to Automata
Temporary Memory
Automaton
Program Memory
05/02/2025 6
Introduction to Automata
Output
Input
X=5
CPU f(x)=28
Program Memory
y=x*x
f(x)=y+3
05/02/2025 7
Introduction to Automata
Why do we need abstract models?
ITCH
SW
BATTERY
input: switch
output: light bulb
actions: flip
switch
states: on, off
05/02/2025 8
Introduction to Automata
A simple “computer”
ITCH
SW
input: switch
output: light bulb bulb is on if and only
if there was an odd
actions: f for “flip number of flips
switch”
states: on, off
05/02/2025 9
Introduction to Automata
Basic Concept
– Every automaton consists of some
essential features as in real Input Tape
computers.
It has a mechanism for reading input.
i.e. Input Tape
The automaton can produce
Finite
output of some form.
Control
If the output is Binary (accept or
reject) - Accepter.
Output sequence in response to an
input sequence- Transducer
The automaton may have a Output Temp
Storage
temporary storage
The most important feature of the
automaton is its control unit.
05/02/2025 10
Different Types of Automata
finite automata Devices with a finite amount of
memory.
Used to recognizing or string
matching.
push-down Devices with infinite memory that
automata can be accessed in a restricted way.
Used to model parsers, etc.
Alphabet
An alphabet is a finite, non-empty set of symbols.
It is represented by ∑.
Ex:
∑={0,1} is binary alphabet.
∑={0,1,2,3,4,5,6,7,8,9} is decimal alphabet.
∑={a,b,c,…..,z} is lower-case alphabet.
05/02/2025 12
Common terms used in Automata
Strings/Words
A string or word is a finite sequence of symbols over ∑.
Ex:
w = 10110 is a string over ∑={0,1}.
05/02/2025 13
Common terms used in Automata
Length of a string
or
Power of ∑
∑k is the set of strings of length k (|w|=k).
Ex:
If ∑={a,b} then
∑0= {Ɛ} , called Epsilon.
∑1 = {a,b}
∑2 = {aa,ab,ba,bb}
05/02/2025 14
Common terms used in Automata
Reverse of a string
Reverse of a string, w is represented as wR.
Ex:
If w=xyz then wR =zyx.
Substrings of a string
If w=xyz then its substrings are:
Ɛ, x, y, z, xy, yz, zx, xyz
05/02/2025 15
Common terms used in Automata
Prefix of a string
If w=xyz then its prefixes are:
Ɛ, x, xy, xyz
Suffix of a string
If w=xyz then its suffixes are:
Ɛ, z, yz, xyz
05/02/2025 16
Common terms used in Automata
Languages
A set of strings, over ∑, is called a language.
Ex:
L1=[w={0,1}*| w has equal number of 0’s and 1’s]
L1={01,10,0011,0101,0110,1010,1001,1100,……}
L2=[w={a,b}*| |w|3]
L2={Ɛ,0,1,00,01,10,11,000,001,010,011,100,101,1
10,111}
05/02/2025 17
Common terms used in Automata
Kleene closure
Kleene closure represented as ∑*, is set of strings of all
possible length.
Ex:
If ∑ ={a,b} then
∑*={Ɛ, a,b,aa,ab,ba,bb,aaa,aab,………..}
05/02/2025 18
Common terms used in Automata
Positive closure
Positive closure represented as ∑+, is set of strings of all
possible length.
∑+=∑1 ∑2 ∑3……….
∑*= ∑0 ∑+
Ex:
If ∑ ={a,b} then
∑+={a,b,aa,ab,ba,bb,aaa,aab,………..}
05/02/2025 19
Finite Automata
a b Magnetic
b tape
a b a a
Reading Head
Output
Finite Control
05/02/2025 20
Applications of Automata
05/02/2025 21
Finite Automata
Finite Automata
05/02/2025 22
DFA
For a DFA the machine moves to a particular unique state from a given
state and given input that is why it is called Deterministic. As the
number of states in DFA are Finite it is called Deterministic Finite
Automata.
a q1
q0
b
q2
05/02/2025 23
Deterministic Finite Automata
05/02/2025 24
DFA
Representation of
o Transition Diagram
o Transition Table
o Transition Function
05/02/2025 25
DFA
Transition Diagram
0 0
1 0
q0 q1 q2
1 1
05/02/2025 26
DFA
Transition Table
q0 q0 q0
q1 q0 q1
*q2 q0 q0
05/02/2025 27
DFA
Transition Function
(q0, 0)= q0
(q0, 1)= q1
(q1, 0)= q2
(q1, 1)= q0
(q2, 0)= q1
(q2, 1)= q2
05/02/2025 28
Example
0 1 0,1
q0 1 q1 0 q2
states
q1 q2 q1
q2 q2 q2
05/02/2025 29
Language of a DFA
M: off on
0 0
1 The set of all string over
q0 q1
1 {0,1} containing even no.
of 1’s
0 1
The set of all string over
1 {0,1} ending with 1’s
q0 q1
0
0 1 0,1
The set of all string over
q0 1 q1 0 q2 {0,1} does not contain 10
as substring
05/02/2025 31
Exercise on DFA
1) Construct the DFA for the set of all string over {a,b}.
2) Construct the DFA for the set of all string over {a,b}
contain exactly 3a’s .
3) Construct the DFA that accepts all string over{a,b}
contains at most 3 a’s
4) Construct the DFA for the even number of a’s over {a,b}.
5) Construct the DFA for the set of all string contain three
consecutive a’s over {a,b}.
6) Construct the DFA that accepts all string over{a,b}
containing aba as substring.
05/02/2025 32
Variation of Finite Automata
05/02/2025 33
NFA
a q1
q0
a
q2
05/02/2025 34
Formal definition of an NFA
05/02/2025 35
Difference between DFA and NFA
The transition from a state is to a single The transition from a state can be to a
particular next state for each input combination of states for each input
symbol. Hence it is called deterministic. symbol. Hence it is called non-
Means moves are unique. δ: Q × Σ → Q deterministic. It has several possible
moves. δ: Q x Σ → 2Q
36
Examples of DFA
05/02/2025 37
Examples of DFA
1
0 1
q0 q1
0
05/02/2025 38
Examples of DFA
0, 1 0, 1
q0 q1 q2
0, 1
05/02/2025 39
Examples of DFA
0 0 1
q0 q1 q2 q3
05/02/2025 40
Examples of DFA
0 0 1
q0 q1 q2 q3
05/02/2025 41
Examples of NFA
a, b
a a b
q0 q1 q2 q3
05/02/2025 42
Examples of NFA
a a c d
q0 q4 q5 q6 q7
a
b d d
q8 q9 q10 q11
05/02/2025 43
Conversion of NFA to DFA
q0 q0 q1
q0 q1
q1 q1 {q0,q1}
1
0 0 0,1
0 1
q0 q0 q1
1 1
q0 q1 [q0,q1]
q1 q1 [q0,q1]
05/02/2025 44
Equivalence of NFA and DFA
05/02/2025 45
Equivalence of NFA and DFA (Proof)
05/02/2025 46
Equivalence of NFA and DFA (Proof)
Basis Step
Let x be the empty string ε.
δD(q0D, x) = δD(q0D, ε)
= q0D
= {q0N }
= δN(q0N, ε)
= δN(q0N, x)
05/02/2025 47
Equivalence of NFA and DFA (Proof)
Inductive Step
Assume that for any y with |y| ≥ 0, δD(q0D, y) = δN(q0N, y).
If we let n = |y|, then we need to prove that for a string z with |z| = n + 1, δD(q0D, z) = δN(q0N, z) .
We can represent the string z as a concatenation of string y (|y| = n) and symbol a from the
alphabet Σ (a ∈ Σ). So, z = ya.
δD(q0D, z) = δD(q0D, ya)
= δD(δN(q0D, y) ,a)
= δD(δN(q0N, y) ,a) By assumption
= p δN(q0N, y) δN(q0N, y) By definition of δD
= δN(q0N, ya)
= δN(q0N, z)
DFA D accepts a string x iff δD(q0D, x) FD . From the above it follows that D accepts x iff δN(q0N, x)
FN = .
So a string is accepted by DFA D if, and only if, it is accepted by NFA N.
05/02/2025 48
NFA with Ɛ- Transition
0 1
ε
q0 q1
05/02/2025 49
Why Ɛ- NFA ?/
05/02/2025 50
Formal definition of an Ɛ- NFA
05/02/2025 51
Example of ε -NFA
a b c
ε ε
q0 q1 q2
05/02/2025 52
Example of ε -NFA
a
ε q1 q2
q0 a
ε
q3 a q4 a q5
05/02/2025 53
ε –Closure of a state
ε ε
q0 q1 q2
05/02/2025 54
Conversion of ε –NFA to NFA
a b c (q0, a)= ε-Closure(ε-Closure(q0), a)
= ε-Closure({ q0,q1,q2},a)
ε ε = ε-Closure(q0)
q0 q1 q2 = {q0, q1, q2}
States ε-Closure a b c
q2 {q2} q2 {q2}
a b c
a, b b, c
q0 q1 q2
a, b, c
05/02/2025 55
Minimization of DFA
05/02/2025 56
Minimization of DFA
0 1
B 1 D
0 A B C
B B D
A 0 1
0 C B C
1 D B E
C E *E B C
1
05/02/2025 57
Minimization of DFA
• Eqivalent State
Two states qi and qj are equivalent or indistinguishable (for the future), if,
when started in these states, every string causes the machine to either end up
in an accepting state for both or end up in a non-accepting state for both.
qi qm
a
qj qn
a
05/02/2025 58
Minimization of DFA
Suppose there is a DFA D < Q, Σ, q0, δ, F > which recognizes a language L. Then
the minimized DFA D < Q’, Σ, q0, δ’, F’ > can be constructed for language L as:
Step 1: We will divide Q (set of states) into two sets. One set will contain all
final states and other set will contain non-final states. This partition is called
0.
Step 2: Initialize k = 1
Step 3: Find k by partitioning the different sets of k-1. In each set of k-1,
we will take all possible pair of states. If two states of a set are
distinguishable, we will split the sets into different sets in k.
Step 4: Stop when k = k-1 (No change in partition)
Step 5: All states of one set are merged into one. No. of states in minimized
DFA will be equal to no. of sets in k.
05/02/2025 59
Minimization of DFA
05/02/2025 60
Minimization of DFA
Transition Table
{A,C} {B} {D} {E}
0 1 0
0
A B C
B B D B 1 D
0
C B C
D B E AC 0 1
0
*E B C
1
E
05/02/2025 61
Minimization of DFA
Step 1: Draw a table for all pairs of states (P,Q) not necessarily
connected directly [All are unmarked initially].
Step 2: Consider every state pair (P,Q) in the DFA where P ∈ F and
Q ∉ F or vice versa and mark (X) them. [Here F is the set of final
states].
05/02/2025 62
Minimization of DFA
05/02/2025 63
Minimization of DFA
0, 1
1 1
B D F
1
0 0
1
0
A C 0 E
1
0
05/02/2025 64
Minimization of DFA
A B C D E F
A
B
C
D
E
F
05/02/2025 65
Minimization of DFA
Step 2: Mark every state pair (P,Q) in the DFA where P ∈ F and Q ∉ F .
A B C D E F
A
B
C X X
D X X
E X X
F X X X
05/02/2025 66
Minimization of DFA
Step 3: − If there is an unmarked pair (P, Q ), such that {δ(P , a), δ (Q , a)} is
marked then mark (P,Q).
A B C D E F
A
B
C X X
D X X
E X X
F X X X X X
05/02/2025 67
Minimization of DFA
•After step 3, we have got state combinations {a, b} {c, d} {c, e} {d, e} that
are unmarked.
•We can recombine {c, d} {c, e} {d, e} into {c, d, e}.
•Hence we got two combined states as − {a, b} and {c, d, e}.
•So the final minimized DFA will contain three states {f}, {a, b} and {c, d,
e}.
0 0 0, 1
1 1
[AB] [CDE] F
05/02/2025 68
Daily Quiz
e) NO
f) YES
g) SOMETIMES
h) Depends on NFA
05/02/2025 69
Daily Quiz
3. Which of the following statements is wrong ?
A. all strings
B. no string
C. ε- alone
D. none of these
05/02/2025 71
Daily Quiz
05/02/2025 72
Daily Quiz
05/02/2025 73
Finite Automata with Output
05/02/2025 74
Finite Automata with Output
05/02/2025 75
Finite Automata with Output
• Mealy Machine
• The out put is associated with transition. The output depends on present
state and present input.
: Q X ∑
• Moore Machine
• The output is associated with present state. The output depends on
present state only.
: Q
05/02/2025 76
Formal Definition of Mealy Machine
05/02/2025 77
Example of Mealy Machine
b/0
a/0
q0
q0 q2, 0 q1, 0
b/0
q1 q2, 0 q1, 1
q1
q2 q2, 1 q1,0
b/1
05/02/2025 78
Formal Definition of Moore Machine
05/02/2025 79
Example of Moore Machine
b b b
a a
q0/0 q1/1 q2/2
q0 q2 q1 0
q1 q2 q1 1
q2 q2 q1 2
05/02/2025 80
Conversion from Mealy machine to Moore machine
Step 1: For each state q determine the number of outputs that are
associated with q in Next state column of transition table of the Mealy
machine.
Step 2: If the outputs corresponding to state q in the next state
columns are same, then retain state q as it is.
Else, break q into different states with the number of new states being
equal to the number of different outputs of q.
Step 3: Rearrange the states and outputs in the format of Moore
machine.
05/02/2025 81
Conversion from Mealy machine to Moore machine
05/02/2025 82
Conversion from Mealy machine to Moore machine
Convert given Mealy machine to Moore machine.
05/02/2025 83
Conversion from Moore machine to Mealy machine
p s q 0
q q r 1
r r s 0
s s p 0
05/02/2025 84
Conversion from Moore machine to Mealy machine
First of all take the Mealy machine transition table format, and copy all
the Moore machine transition table states into Mealy machine transition
table.
Present Next State
State
a b
p s q
q q r
r r s
s s p
05/02/2025 85
Conversion from Moore m/c to Mealy m/c
Now in the Moore machine, the output of state p is 0. So make the output of p
in the Mealy machine next state column of the above table is 0. Same process
is repeated for q, r and s.
Moore Machine Mealy Machine
Present Next State
Present Next Output State
State State a b
a b
p s, 0 q, 1
p s q 0 q q, 1 r, 0
q q r 1 r r, 0 s, 0
r r s 0 s s, 0 p, 0
s s p 0
05/02/2025 86
Difference Between Mealy And Moore Machine
Output Function : Q X ∑ : Q
Counter A counter is not a Mealy A counter is a Moore machine.
machine.
Design Not necessarily easy to design. Easy to design.
It produce n length output It produce n+1 length output
Length of Out put String string corresponding to n length string corresponding to n length
input String input String
05/02/2025 87
Daily Quiz
1. Given: ∑= {a, b}L= {xϵ∑*|x is a string combination}∑4 represents which
among the following? *
A. {aa, ab, ba, bb}
B. {aaaa, abab, ε, abaa, aabb}
C. {aaa, aab, aba, bbb}
D. All of the mentioned
2. Converting each of the final states of F to non-final states and old non-final
states of F to final states, FA thus obtained will reject every string belonging
to L and will accept every string, defined over Σ, not belonging to L. is called
E. Transition Graph of L
F. Regular expression of L
G. Complement of L
H. Finite Automata of L
05/02/2025 88
Daily Quiz
4. The part of an FA, where the input string is placed before it is run, is
called ______
E. State
F. Transition
G. Input Tape
D. Output Tape
05/02/2025 89
Daily Quiz
05/02/2025 90
Daily Quiz
7. John is asked to make an automaton which accepts a given string for all the
occurrence of ‘1001’ in it. How many number of transitions would John use such
that, the string processing application works?
A. 9
B. 11
C. 12
D. 15
8. The total number of states to build the given language using DFA:
L= {w | w has exactly 2 a’s and at least 2 b’s}
E. 10
F. 11
G. 12
H. 13
05/02/2025 91
Daily Quiz
10. Let N (Q, ∑, δ, q0, A) be the NFA recognizing a language L. Then for
a DFA (Q’, ∑, δ’, q0’, A’), which among the following is true?
a) Q’ = P(Q)
b) Δ’ = δ’ (R, a) = {q ϵ Q | q ϵ δ (r, a), for some r ϵ R}
c) Q’={q0}
d) All of the mentioned
05/02/2025 92
Weekly Assignment
1. Design a deterministic finite automaton(DFA) for the following
language over the set of input alphabet {0,1}
[CO1]
• All strings of 0’s and 1’s such that no of 0’s are even and 1’s are odd.
• All strings of 0’s and 1’s with at least two consecutive 0’s.
• All strings of 0’s and 1’s beginning with 1 and not having two
consecutive zeroes.
• All strings of 0’s and 1’ s not containing 101 as substring.
• All strings of 0’s and 1’s whose last two symbols are same.
05/02/2025 93
Weekly Assignment
3. Prove that NFA is equivalent to DFA. [CO1]
4. Construct NFA accepting the set of all strings over {a, b} ending in
aba. Use it to construct a DFA accepting the same set of strings.
[CO1]
5. Design a NFA with epsilonthat accepts {a, b}*baaa.[CO1]
6. Design a NFA that accepts (a+b)*(ab+bba) (a+b)* i.e. strings
containing either ab or bba as substring . convert it into DFA.
[CO1]
7. Differentiate between DFA and NDFA with suitable example?
[CO1]
8. Describe various Application and Limitations of Finite Automata.
[CO1]
05/02/2025 94
Weekly Assignment
2. Design a Non-deterministic finite automaton(NFA) for the following
language over the set of input alphabet {0,1}
[CO1]
• All strings of 0’s and 1’s such that 3rd symbol from right end is 1.
• All strings of 0’s and 1’s such that either the 2nd or 3rd position from
the right end has a 1.
• All strings of 0’s and 1’s satisfying 1m01n : m, n>=1.
• All strings of 0’s, 1’s and 2’s with any no of 0’s followed by any no of
1’s and any no of 1’s followed by any no of 2’s.
• All strings of 0’s and 1’s ending in1 and not containing substring 00.
05/02/2025 95
MCQ s
05/02/2025 96
MCQ s
ANS : (A)
05/02/2025 97
MCQ s
05/02/2025 98
MCQ s
6. If two finite state machines are equivalent, they should have the
same number of
A. states
B. edges
C. states and edges
D. none of these
05/02/2025 99
MCQ s
05/02/2025 100
Expected Questions for University Exam
• Design a NFA that accepts all the strings for input alphabet {a,b}
containing the substring abba.
• Convert NFA into equivalent DFA by taking any suitable example.
• Design the DFA that accepts an even number of a’s and even number
of b’s.
• Construct the minimum state automata equivalent to DFA described
below:
05/02/2025 101
Summary
05/02/2025 102
References
05/02/2025 103
Thank You
05/02/2025 104