Unit1 Sana Anjum
Unit1 Sana Anjum
Greater Noida
Unit:1
Finite Automata
Sana Anjum
Assistant Professor
B. Tech
(Computer Science & Engineering) Computer Science and
4th Semester Engineering
Lucknow
Computer Science
• Automaton is nothing but a machine which accepts the strings of a
language L over an input alphabet Σ. There are four different types
of Automata that are mostly used in the theory of computation
(TOC).
• Finite-state machine (FSM).
• Pushdown automata (PDA).
• Linear-bounded automata (LBA).
• Turing machine (TM).
Bloom’s
CO At the end of course , the student will be able to
(KL)
CO1 Design and Simplify automata for formal languages and K6
transform non-deterministic finite automata to deterministic
finite automata.
CO2 Identify the equivalence between the regular expression and K3
finite automata and apply closure properties of formal
languages to construct finite automata for complex problems.
CO3 Define grammar for context free languages and use pumping K3
lemma to disprove a formal language being context- free.
CO4 Design pushdown automata (PDA) for context free languages K6
and Transform the PDA to context free grammar and vice-versa.
CO5 Construct Turing Machine for recursive and recursive K6
enumerable languages. Identify the decidable and undecidable
problems.
Contd..
Contd..
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO1 PO11 PO1
0 2
CO1
2 2 3 3 2 2 - - 2 1 - 3
CO2
1 3 2 3 2 2 - 1 1 1 2 2
CO3
2 2 3 2 2 2 - 2 2 1 2 3
CO4
2 2 2 3 2 2 - 2 2 1 1 3
CO5
3 2 2 2 2 2 - 2 1 1 1 2
Average
2 2.2 2.4 2.6 2 2 - 1.4 1.6 1 1.2 2.6
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO1 PO11 PO1
0 2
CO1 2 2 3 3 2 2 - - 2 1 - 3
Design and develop the hardware sensor devices and related interfacing
PSO2: software systems for solving complex engineering problems.
PSO
CO
PSO1 PSO2 PSO3 PSO4
CO1 2 2 2 2
CO2 2 2 1 1
CO3 2 2 1 1
CO4 2 2 1 1
CO5 2 2 2 2
Average 2 2 1.4 1.4
PEO3:To effectively bridge the gap between industry and academia through
effective communication skill, professional attitude, ethical values and a desire
to learn.
PEO
CO
PEO1 PEO2 PEO3 PEO4
CO1 2 2 1 2
CO2 2 2 1 1
CO3 2 2 2 2
CO4 2 2 1 1
CO5 2 2 1 2
Average 2 2 1.2 2
Subject Result:
Section A: 95.65%
Section B: 97.14%
Section C: 84.51%
Section D: 94.29%
Finite Automata 3 - - - -
Temporary Memory
Automaton
Program Memory
Output
Input
X=5
CPU f(x)=28
Program Memory
y=x*x
f(x)=y+3
05/19/2024 Sana Anjum ACSE0404 (TOAFL) Unit I 30
Introduction to Automata
BATTERY
input: switch
output: light bulb
actions: flip switch
states: on, off
A simple “computer”
ITCH
SW
input: switch
output: light bulb bulb is on if and only if
there was an odd number of
actions: f for “flip switch” flips
states: on, off
Another “computer” 1
1
start off off
1
2 2
BATTERY 2 2
1
2
off on
1
A Design Problem
1 4
?
5
BATTERY
Can you design a circuit where the light is on if and only if all the
switches were flipped exactly the same number of times?
Such devices are difficult to reason about, because they can be
designed in an infinite number of ways
A Design Problem
• By representing them as abstract
computational devices, or automata, we will
learn how to answer such questions
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/19/2024 Sana Anjum ACSE0404 (TOAFL) Unit I 36
Different Types of Automata
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.
Strings/Words
A string or word is a finite sequence of symbols over ∑.
Ex:
w = 10110 is a string over ∑={0,1}.
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}
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
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
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={0,1}*| |w|3]
L2={Ɛ,0,1,00,01,10,11,000,001,010,011,100,101,1
10,111}
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,………..}
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,………..}
G
xαy⇒xβy
The set of all strings that can be derived from a grammar is said to be
the language generated from that grammar.
A language generated by a grammar G is a subset formally defined by
L(G)={W|W ∈ ∑*, S ⇒G W}
1. If there is a grammar
G: N = {S, A, B} T = {a, b} P = {S → AB, A → a, B → b}
• Here S produces AB, and we can replace A by a, and B by b.
Here, the only accepted string is ab, i.e.,
• L(G) = {ab}
According to Noam Chomsky, there are four types of grammars − Type 0, Type
1, Type 2, and Type 3. The following table shows how they differ from each
other
Example1 :
X→ε
• X → a | aY
• Y→b
Example 2:
The language 0(10)* is generated by
the right linear grammar: S → 0A
A → 10 A / ε
The left linear grammar : S → S10 / 0
• AB → AbBc
• A → bcA
• B→b
• S → ACaB
• Bc → acB
• CB → DB
• aD → Db
a b Magnetic
b tape
a b a a
Reading Head
Output
Finite Control
Finite Automata
a q1
q0
b
q2
Representation of
o Transition Diagram
o Transition Table
o Transition Function
Transition Diagram
0 0
1 0
q0 q1 q2
1 1
M={ {q0, q1, q2}, {0,1}, , q0, q2}
Transition Table
q0 q0 q1
q1 q0 q2
*q2 q0 q0
Transition Function
(q0, 0)= q0
(q0, 1)= q1
(q1, 0)= q2
(q1, 1)= q0
(q2, 0)= q1
(q2, 1)= q2
0 1 0,1
q0 1 q1 0 q2
states
q1 q2 q1
q2 q2 q2
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
a q1
q0
a
q2
1
0 1
q0 q1
0
0, 1 0, 1
q0 q1 q2
0, 1
0 0 1
q0 q1 q2 q3
0 0 1
q0 q1 q2 q3
a, b
a a b
q0 q1 q2 q3
a a c d
q0 q4 q5 q6 q7
a
b d d
q8 q9 q10 q11
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]
Basis Step
Let x be the empty string ε.
δD(q0D, x) = δD(q0D, ε)
= q0D
= {q0N }
= δN(q0N, ε)
= δN(q0N, x)
0 1
ε
q0 q1
a b c
ε ε
q0 q1 q2
a
ε q1 q2
q0 a
ε
q3 a q4 a q5
ε ε
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/19/2024 Sana Anjum ACSE0404 (TOAFL) Unit I 97
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
• 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
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.
Transition Table
0 1
Find Equivalence classes
A B C
0= {A,B,C,D} {E}
B B D 1= {A,B,C} {D} {E}
C B C 2= {A,C} {B} {D} {E}
D B E 3= {A,C} {B} {D} {E}
*E B C 2= 3 ,so stop here.
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
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].
0, 1
1 1
B D F
1
0 0
1
0
A C 0 E
1
0
A B C D E F
A
B
C
D
E
F
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
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
•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
• 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/19/2024 Vineet
Sana Kumar
Anjum KCS-402
ACSE0404 (TOAFL)
(TOAFL) Unit I 113
Unit I
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/19/2024 Vineet
Sana Kumar
Anjum KCS-402
ACSE0404 (TOAFL)
(TOAFL) Unit I 115
Unit I
Example of Moore Machine
b b b
a a
q0/0 q1/1 q2/2
q0 q1 Q0 0
q1 q2 q1 1
q2 q2 q1 2
05/19/2024 Sana Anjum ACSE0404 (TOAFL) Unit I 116
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.
p s q 0
q q r 1
r r s 0
s s p 0
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
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/19/2024 Sana Anjum ACSE0404 (TOAFL) Unit I 122
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
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
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
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
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
e) NO
f) YES
g) SOMETIMES
h) Depends on NFA
A. all strings
B. no string
C. ε- alone
D. none of these
ANS : (A)
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
1) Construct the DFA for the set of all string over {a,b} contain
exactly 3a’s .
2) Construct the DFA that accepts all string over{a,b} contains
at most 3 a’s
3) Construct the DFA for the even number of a’s over {a,b}.
4) Construct the DFA for the set of all string contain three
consecutive a’s over {a,b}.
5) Construct the DFA that accepts all string over{a,b} containing
aba as substring.
[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.
https://drive.google.com/drive/folders/19Eia3VHCl3627foiH6V_j-p4X9
ZkyyC7?usp=sharing
• 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: