Atcd Unit 1
Atcd Unit 1
UNIT-1
Finite Automata
Syllabus:
Automata: Need for Automata Theory, Chomsky hierarchy, Acceptance of a string, Design of
NFA with Є, NFA without Є, DFA, Equivalence of NFA, DFA
Finite Automata Conversions: Conversion from NFA Є to NFA, NFA to DFA, Minimization of
DFA, Moore and Mealy Machines
Automata Theory
Automata theory is the study of abstract computing devices or machines.
i.e., the study of what can be done by computers in principle and what can be
done in practice.
In automata theory, we study about computers by building abstract
mathematical and model, study their limitations by analyzing the types of
inputs which they operate successfully.
Three Central Concepts of Automata Theory:
Language: a system suitable for the expression of ideas, facts, or concepts.
Automata: an abstract mathematical and theoretical model of a computer.
(Language Acceptor or Language Recognizer)
Grammar: a mathematical mechanism to describe language (Language
Generator)
Need for Automata Theory:
Automata theory provides concepts and principles that help us understand
the general nature of the computer.
There are immediate and important applications of automata theory such as
digital design, programming languages, and compilers and so on.
Through automata theory we are able to understand how computer compute
function and solve problems, what are computable or decidable problems.
Finite automata are useful for building several different kinds of software
including the lexical analysis component of a compiler and systems for
verifying the correctness of circuits or protocols.
Automata theory concepts help us understand what we can expect from our
software.
Automata theory is used in AI to model and analyze the behaviour of
intelligent systems.
Three basic Concepts of Automata Theory:
Alphabet (∑): a finite, non-empty set of symbols.
String (w): a finite sequence of symbols chosen from some alphabet.
Language (L): a set of strings over the given alphabet.
Alphabet:
A finite, nonempty set of symbols is called alphabet.
Symbols in alphabet are used to form strings in the language.
Conventionally we use the symbol ∑ for an alphabet.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 1
III B.Tech AID R20 ATCD-UNIT-1
Note:
Symbols are indivisible (atomic) objects or entity that cannot be defined.
Symbol is any single object such as a,b,0,1,#,$
String:
A finite sequence of symbols chosen from some alphabet is called string.
i.e.; a string over ∑is a finite sequence of symbols in ∑
String must be finite but can be empty or non-empty.
For example, if the alphabet Σ = {a, b}, then abab and aaabbba are strings
on Σ.
For example, if the alphabet Σ = {0, 1}, then 011100, 00000,11111,1010101
are strings on Σ.
The set of all strings over ∑ will be written ∑*
Language:
A set of strings drawn from some alphabet is called language.
A language over ∑ is a subset of ∑* i.e.; L ∑*
Language can be empty or non-empty and finite or non-finite.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 2
III B.Tech AID R20 ATCD-UNIT-1
Note:
Σ, Σ*, , { } are languages.
Smallest language over Σ is
Largest language over is Σ is Σ *
A language over Σ need not includes strings with all the symbols of Σ
Languages can have an infinite number of strings are restricted to consist of
strings drawn from one fixed finite alphabet.
Note:
Alphabet and string must be finite but language can be finite or infinite.
Alphabet must be non-empty but string and language can be empty or non-empty.
Operation on Alphabet:
(Powers of Alphabet)
If Σ is an alphabet, we can express the set of all strings of a certain length
from that alphabet by using an exponential notation. We define Σk to be
the set of strings of length k, each of whose symbols is in Σ.
Σk = { w / |w| =k & w is string drawn from Σ }
Example: If Σ = {0, 1}, then Σ1 = {0, 1}, Σ2 = {00, 01, 10, 11},
Σ3 = {000,001,010,011,100,101,110,111} and so on.
Note that Σ0 = {ε}, regardless of what alphabet Σ is. That is, ε is the only
string whose length is 0.
If Σ is an alphabet, then we use Σ* to denote the set of strings obtained by
concatenating zero or more symbols from Σ. The set Σ* always contains
∑* = ∑0 ∑1 ∑2.... = i 0 ∑i = {w/ |w| >=0 & w is string formed
using ∑ }
If Σ is an alphabet, then we use Σ to denote the set of strings obtained by
+
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 3
III B.Tech AID R20 ATCD-UNIT-1
∑* . ∑ * = ∑*
∑+ . ∑+ = ∑+ - ∑1
∑ . ∑* = ∑*.∑ = ∑+
Basic Operations on Strings:
1. Length of string
2. Concatenation of string
3. Reverse of string
4. Substring
5. Prefix and Suffix of string
6. Subsequence
Length:
The length of a string w, denoted by |w|, is the number occurrence of symbols
in the string. i.e.; Number of positions for symbols in the string.
For instance string 01101 has length 5
We will frequently need to refer to the empty string, which is a string
with no symbols at all. It will be denoted by .
For example |01101| = 5 , || = 0
Note:
is only string whose length is 0
Concatenation:
If x and y are two strings over an alphabet, the concatenation of x and y is
written xy and consists of the symbols of x followed by those of y.
If x = ab and y = bab, for example, then xy = abbab and yx = babab.
When we concatenate the null string with another string, the result is
just the other string (for every string x, x = x = x);
In general, for two strings x and y, |xy| = |x| + |y|.
wk represent string obtained by concatenating string w, k times
Ex: If w=ab then w3 = abababa
Reverse:
The reverse of a string is obtained by writing the symbols in reverse
order.
If w is a string w = a1a2 ... an, then its reverse wR is wR = an ... a2 a1.
For example, if abbaaa is string, then its reverse is aaabba
In general |w| =|wR|
Substring
Any string of consecutive symbols in some string w is said to be substring
of w.
For example, if w = abcd then {, a, b, c, d, ab, bc, cd, abc, bcd, abcd} is
the set of all its substrings.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 4
III B.Tech AID R20 ATCD-UNIT-1
Difference:
If L1 and L2 are two languages over an alphabet Σ. Then the difference of
L1 and L2 is denoted by L1 - L2.
Example: L1= {0, 01,011} and L2= {01}, then L1 - L2= {0,011}
Complement:
The complement of a language is defined with respect to Σ*; that is, the
complement of L is
Example:
If Σ = {a,b} and L={a,b,aa} then
L = Σ* - L={ ε,a,b,aa,bb,ab.........}-{a,b,aa} = {ε,bb,ab,ba.........}
Reverse:
The reverse of a language is the set of all string reversals, that is,
Example:
If L= {0, 011, 0111}, then LR = {0, 110, 1110}
Concatenation:
The concatenation of two languages L1 and L2 is the set of all strings
obtained by concatenating any element of L1 with any element of L2;
specifically,
Kleene Closure:
For a language L over an alphabet ∑, we use the notation L* to denote the
language of all strings that can be obtained by concatenating zero or more
strings in L.
This operation on a language L is known as the Kleene star, or Kleene
closure, after the mathematician Stephen Kleene.
= i 0
L
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 6
III B.Tech AID R20 ATCD-UNIT-1
Positive Closure
For a language L over an alphabet Σ, we use the notation L + to denote the
language of all strings that can be obtained by concatenating one or more
strings in L. This operation on a language L is known as the positive
closure.
= i 1
Li
Note:
Lk : set of all strings that can be obtained by concatenating k strings of L
∑k : set of strings of length k each of whose symbols is in ∑
wk: string obtained by concatenating w, k times
ak : string obtained by concatenating a, k times
L0 = {}
∑0 = {}
w0 =
a0 =
L. = L
L. =
* = {}
{}* ={}
L+ = L* if L contains
(L*)* = L*
k = for k>0
Chomsky Hierarchy
The Chomsky hierarchy is a classification of formal languages based on their
generative power. Proposed by Noam Chomsky in 1956, this hierarchy
categorizes languages into four types: Type 0, Type 1, Type 2, and Type 3.
Each type corresponds to a specific class of automaton that can recognize or
generate the languages in that category.
i.e.; the four classes of languages: regular, context-free, context-sensitive, and
recursively enumerable—make up what is often referred to as the Chomsky
hierarchy.
Each level in the Chomsky hierarchy is a strict superset of the levels
below it, meaning every regular language is context-free, every context-
free language is context-sensitive, and every context-sensitive language is
recursively enumerable.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 7
III B.Tech AID R20 ATCD-UNIT-1
The classes are nested, with type 0 being the largest and most general,
and type 3 being the smallest and most restricted.
Chomsky Hierarchy contains 4 classes of languages, each having a
corresponding model of computation and a corresponding type of grammar.
Regular Grammar(RG) generates regular language(RL) which is accepted by
Finite Automata(FA)
Context Free Grammar(CFG) generates Context Free Language(CFL) which
is accepted by Push Down Automata(PDA)
Context sensitive Grammar(CSG) generates Context Sensitive
Language(CSL) which is accepted by Linear Bounded Automata(LBA)
Recursive Enumerable Grammar(REG) generates Recursive Enumerable
Language(REL) which is accepted by Turing Machine(TM)
A language L is recursively enumerable if there is a TM that accepts L.
A language is a context-sensitive language (CSL) if it can be generated by a
context-sensitive grammar.
Regular languages are the simplest and most restrictive class in the hierarchy
and are used to describe simple patterns like those found in regular
expressions.
Finite Automata Model
A FA is model that has a finite set of states and control moves from one state
to another state in response to external inputs.
i.e.; FA involves states and transitions among states in response to inputs
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 8
III B.Tech AID R20 ATCD-UNIT-1
Example:
Note:
The term deterministic refers to the fact that on each input there is one and only
one state to which the automaton can transition from its current state.
DFA operation:
A deterministic finite automata operates in the following manner:
At the initial time, it is assumed to be in the initial state q0, with its
input mechanism on the leftmost symbol of the input string. During
each move of the automaton, the input mechanism advances one
position to the right, so each move consumes one input symbol.
When the end of the string is reached, the string is accepted if the
automaton is in one of its final states. Otherwise the string is
rejected.
The input mechanism can move only from left to right and reads
exactly one symbol on each step. The transitions from one internal
state to another are governed by the transition function δ
Notations for DFA:
There are two preferred notations for representing transition function for
automata:
1. A transition diagram, which is a graph.
2. A transition table, which is a tabular listing of the δ function,
which by implication tells us the set of states and the input
alphabet.
1. Transition Diagram:
A transition diagram for a DFA, M = (Q, Σ, δ, q0, F) is a graph defined as
follows:
For each state in Q there is a node.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 10
III B.Tech AID R20 ATCD-UNIT-1
For each state q in Q and each input symbol a in Σ, let δ (q, a) = p, then
the transition diagram has an arc from node q to node p, labelled a. If
there are several input symbols that cause transitions from q to p, then
the transition diagram can have one arc, labelled by the list of these
symbols.
There is an arrow into the start state q0, labelled Start. This arrow does
not originate at any node.
Nodes corresponding to accepting states (those in F) are marked by a
double circle. States not in F have a single circle.
Example:
Figure: The transition diagram for the DFA accepting all strings with a substring 01
2. Transition Tables
A transition table is a conventional, tabular representation of a function
like δ that takes two arguments and returns a value.
The rows of the table correspond to the states, and the columns
correspond to the inputs.
The entry for the row corresponds to state q and the column corresponds
to input a is the state δ(q, a)
Start state is marked as arrow and final states are marked with asterisk.
Example:
States Inputs
0 1
q0 q2 q0
*q1 q1 q1
q2 q2 q1
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 11
III B.Tech AID R20 ATCD-UNIT-1
= (δ(q0,1),1001)
= (q0,1001)= ( δ (q0,1),001)
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 12
III B.Tech AID R20 ATCD-UNIT-1
= (q0,001) = (δ (q0,0),01)
= (q2,01) = (δ (q2,0),1)
= (q2,1) = δ (q2,1) =q1 (final state) Accepted
Processing string using extended function (q,wa) = δ ( (q,w),a)) :
(q0, 11001)
= δ ( (q0, 1100), 1)
= δ (δ ( (q0, 110),0),1)
= δ (δ (δ ( (q0, 11),0),0),1)
= δ(δ (δ (δ ( (q0,1),1),0),0),1)
= δ(δ (δ (δ (δ(q0,1),1),0),0),1)
= δ(δ (δ (δ (q0,1),0),0),1)
= δ(δ (δ (q0,0),0),1)
= δ(δ (q2,0),1)
= δ(q2,1) = q1 (final state) Accepted
The language of DFA is the set of all strings that result in a sequence of
state transitions from the start state to an accepting state.
i.e.; the language accepted by a DFA, M = (Q, Σ, δ, q0, F) is the set of all
strings on Σ accepted by M.
In formal notation,
L(M) = { w ∑* : (q0,w) F}
Design of DFA
(Finding DFA for given language)
The definitions of various states in DFA are as follows:
Starting (or Initial) State: The state where the DFA begins its
processing. There is always exactly one starting state in a DFA.
Final (or accepting) States: States where the DFA accepts the
input string if it ends in one of these states. There can be one or
more final states in a DFA.
Non-Accepting States: States that are not final states. The number
of non-accepting states is the total number of states minus the
number of final states.
Dead (or Trap) States: A state from which no sequence of inputs
can lead to a final state. In a DFA for a non-empty language, there
is typically at most one dead state. This state has self-loops for all
input symbols, leading only to itself, and cannot transition to any
other state.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 13
III B.Tech AID R20 ATCD-UNIT-1
Note:
Number of states in DFA:
Starting State: 1 (always exactly one)
Final States: At least 1 (for a non-empty language)
Non-Accepting States: 0 or more
(Total number of states - number of final states)
Dead States: at most 1 (0 or 1)
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 14
III B.Tech AID R20 ATCD-UNIT-1
Example 1: Design a DFA that accept set of strings, such that every string ends
with 00, over alphabet {0, 1}
Transition Diagram:
Transition Table:
Transition Function:
DFA, M = (Q, Σ, δ, q0, F) where
Q = {q0, q1, q2}
Σ = {0,1}
Start State=q0
F= {q2}
δ is defined as: δ(q0,0) =q1, δ(q0,1) = q0
δ(q1,0)=q2 , δ(q1,1) = q0
δ(q2,0) =q2 , δ(q2,1) = q0
Example1: Construct a DFA accepting all strings w over {0,1} such that the
number of l' s in w is 3 mod 4.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 15
III B.Tech AID R20 ATCD-UNIT-1
Example3: Find a deterministic finite accepter that recognizes the set of all
strings on Σ= {a,b} starting with the prefix ab.
Example4: Find a DFA that accepts all the strings on {0,1}, except those
containing the substring 001.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 16
III B.Tech AID R20 ATCD-UNIT-1
Example5: Find a deterministic finite accepter that recognizes the set of all
strings on Σ= {a,b} starting with the prefix ab.
Example7: Find DFA that accepts all strings over {0, 1} with substring 01
Problem: Find a deterministic finite accepter that recognizes the set of all strings
on Σ= {a,b} starting with the prefix aba.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 17
III B.Tech AID R20 ATCD-UNIT-1
Problem: Construct DFA that accepts set of all strings over {0, 1} of length 2.
Problem: Design a DFA for language accepting all strings over {0, 1}containing
101 as substring.
Problem: Construct a DFA for the set of strings over{0,1} having bca as substring
Problem: Design a DFA that accept set of all strings over Σ = {a, b} with no more
than three a’s
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 18
III B.Tech AID R20 ATCD-UNIT-1
Problem: Give DFA’s accepting the following languages over the alphabet {0, 1}.
(a) The set of all strings ending in 00.
(b) The set of all strings with three consecutive 0’s (not necessarily at the end
(d) The set of all strings whose tenth symbol from the left end is a 1.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 19
III B.Tech AID R20 ATCD-UNIT-1
(e) The set of strings that either begin or end (or both) with 01
(f) The set of strings such that the number of 0’s is divisible by five, and the
number of 1’s is divisible by 3.
Problem: Obtain DFAs to accept strings of 0’s and 1’s having 01 as substring.
Problem: Obtain a DFA to accept strings of a’s and b’s starting with the string ab.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 20
III B.Tech AID R20 ATCD-UNIT-1
Problem: Draw a DFA to accept string of 0’s and 1’s ending with the string 011.
Problem: Design a DFA to accept string of 0’s & 1’s, whose length is multiple of 3.
Problem: Obtain a DFA to accept strings of a’s and b’s having a sub string aa
Problem: Construct DFA accepting binary strings with two consecutive 0's.
Problem: Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and
ends with 0.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 21
III B.Tech AID R20 ATCD-UNIT-1
Problem: Construct a finite automata for the language {0n | n mod 3 = 2, n ≥ 0}.
Problem: Given Σ = {a, b}, construct a DFA which recognize the language
L= {bm abn :m,n>0}.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 22
III B.Tech AID R20 ATCD-UNIT-1
Problem: Design a DFA to accept the binary numbers which are divisible by 5.
Problem: Construct a DFA accepting all string w over {0, 1}, such that number of
1's in w is 3 mod 4.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 23
III B.Tech AID R20 ATCD-UNIT-1
00101
Transition Table:
Where is defined as
(q0,0) = {q0,q1}
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 24
III B.Tech AID R20 ATCD-UNIT-1
(q0,1) = {q0}
(q1,0) =
(q1,1) = {q2}
(q2,0) =
(q2,1) =
Example2:
Significance of NFA:
NFA is an extension of the behaviour of DFA and in some cases greatly
simplifies the description of automata
It is useful because constructing an NFA to recognize a given language is
sometimes much easier than constructing a DFA for that language.
Using greater flexibility of NFA, language recognizer can be design
without actually extending the class of language.
Certain theoretical results are more easily established for NFA's than for
DFA's.
Non-determinism is sometimes helpful in solving problems easily.
Non-determinism is an effective mechanism for describing some
complicated languages concisely.
A nondeterministic algorithm that can make the best choice would be
able to solve the problem without backtracking. For this reason, Non-
deterministic mechanisms can serve as models of search and backtrack
algorithms.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 25
III B.Tech AID R20 ATCD-UNIT-1
Note:
Accepting power of NFA= Accepting power of DFA.
NFA is a theoretical engine and is not implementable, but it is very easy to design
compare to DFA.
No concept of dead state, therefore complementation of DFA is also not possible.
NFA will respond for only valid strings and no need to respond for invalid strings. (it
is a Incomplete system)
Problem: Design an NFA in which all the string over {0,1} contain a substring
1110.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 26
III B.Tech AID R20 ATCD-UNIT-1
Design an NFA with ∑ = {0, 1} accepts all string in which the third symbol
from the right end is always 0.
Note:
DFA: For each state and input symbol, there is exactly one transition to a next state.
NFA: For each state and input symbol, there can be zero, one, or multiple transitions
to next states.
Conversion of NFA to DFA
Let given NFA is M=(Q,∑,,q0,F),the equivalent DFA M’=(Q’,∑,
’,q0’,F’) can be constructed by subset construction method as fallows
i) From the states that are subset of states of given NFA ,start
construction of ’ for[q0] i,e starting state is [q0]
ii) Continue the process of constructing ’ by considering only new states
appearing earlier under input columns using
’(S,a) = U (p,a)
P in S
iii)Stop the process of constructing when no new state appear under input
columns
iv) F’(set of final sates in DFA) is the set of all subsets of Q which are
having any final state of given NFA
Example:
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 27
III B.Tech AID R20 ATCD-UNIT-1
State 0 1
→q0 q0 q1
q1 {q1, q2} q1
State 0 1
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 28
III B.Tech AID R20 ATCD-UNIT-1
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 29
III B.Tech AID R20 ATCD-UNIT-1
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 30
III B.Tech AID R20 ATCD-UNIT-1
Procedure
(Table filling algorithm or Myhill-Nerode Algorithm)
1. Remove all the states that are unreachable from the initial state via any
set of the transition of DFA.
2. Draw the transition table for given DFA.
3. A table is constructed with an entry for each pair of states.
4. Initially X place in each entry corresponding to one final state and one
non-final state.
5. Next, X is placed in entry corresponding to the pair (p,q) if δ (q, a) = r
, δ (r, a) = s and pair(r,s) is marked as X, for any a ε ∑
6. After applying above steps for all the pairs remaining pairs are
equivalent. All equivalent pairs are merged and used with single state.
Example:
Given DFA:
Minimization Table:
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 31
III B.Tech AID R20 ATCD-UNIT-1
Minimal DFA:
Types of states:
Unreachable states are the states that are not reachable from the initial state
of the DFA, for any input string. These states can be removed.
Dead states are the states from which no final state is reachable. These
states can be removed unless the automaton is required to be complete
Non-distinguishable states (Equivalent states) are those that cannot be
distinguished from one another for any input string. These states can be
merged.
i.e.; two states p, q ∈ Q are equivalent, if for every string x ∈ Σ∗ the state
that DFA reaches from p given x is accepting if and only if the state that
DFA reaches from q given x is accepting.
Distinguishable(distinct) states:
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 32
III B.Tech AID R20 ATCD-UNIT-1
Example1:
Example2:
Significance of ε-NFA
ε–NFA allows ε-transition but each ε along a path is invisible
i.e. It contributes nothing to the string along the path.
ε -NFA simplifies the design of FA
ε –NFA’s can be converted DFA’s accepting the same language
This is very helpful when we study regular expression (RE) and prove the
equivalence between the class of language accepted by RE and finite
automata.
Equivalence between Null ε -NFA to NFA
There will be no change in the initial state.
No change in the total no. of states
May be change in the number of final states.
All the states will get the status of the final state in the resulting NFA,
whose €-closure contains at least one final state in the initial €-NFA.
ε-closure:
ε-closure (q) is defined as set of states that can be reached from q using
only epsilon transitions.
Formally ε-closure (q) is defined recursively as:
State q is in ε-closure (q)
If state p is in ε-closure (q) and there is transition from state p to
state r labelled ,then r is in ε-closure (q)
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 33
III B.Tech AID R20 ATCD-UNIT-1
Example:
Note:
ε-closure (q) always include q
ε-closure of any state is always a non-empty and finite set of states.
ε-closure () =
n 1
ε-closure (q0 ,q1, ... ,qn-1) = ε-Closure (q )
i
i 0
Example:
Solution:
We will first obtain ε-closure of each state i.e., we will find ε-reachable states
from the current state.
Hence,
ε-closure(q0) = {q0,q1,q2}
ε-closure(q1) = {q1,q2}
ε-closure(q2) = {q2}
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 34
III B.Tech AID R20 ATCD-UNIT-1
Now we will obtain 𝛿’ transitions for each state on each input symbol as shown
below:
δ'(q0, 0) = ε-closure(δ(ε-closure(q0),0))
= ε-closure(δ(q0,q1,q2), 0))
= ε-closure(δ(q0, 0) ∪ δ(q1, 0) U δ(q2, 0) )
= ε-closure(q0 U Φ ∪ Φ)
= ε-closure(q0)
= {q0,q1, q2}
δ'(q0, 1) = ε-closure(δ(ε-closure(q0),1))
= ε-closure(δ(q0,q1,q2), 1))
= ε-closure(δ(q0, 1) ∪ δ(q1, 1) U δ(q2, 1) )
= ε-closure(Φ ∪q1 U Φ)
= ε-closure(q1)
= {q1, q2}
δ'(q0, 2) = ε-closure(δ(ε-closure(q0),2))
= ε-closure(δ(q0,q1,q2), 2))
= ε-closure(δ(q0, 2) ∪ δ(q1, 2) U δ(q2, 2) )
= ε-closure(Φ U ΦU q2)
= ε-closure(q2)
= {q2}
δ'(q1, 0) = ε-closure(δ(ε-closure(q1),0))
= ε-closure(δ(q1,q2), 0))
= ε-closure(δ(q1, 0) U δ(q2, 0) )
= ε-closure(Φ ∪ Φ)
= ε-closure(Φ)
=Φ
δ'(q1,1) = ε-closure(δ(ε-closure(q1),1))
= ε-closure(δ(q1,q2), 1))
= ε-closure(δ(q1, 1) U δ(q2, 1) )
= ε-closure(q1 ∪ Φ)
= ε-closure(q1)
= {q1,q2}
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 35
III B.Tech AID R20 ATCD-UNIT-1
δ'(q1, 2) = ε-closure(δ(ε-closure(q1),2))
= ε-closure(δ(q1,q2), 2))
= ε-closure(δ(q1, 2) U δ(q2, 2) )
= ε-closure(Φ ∪ q2)
= ε-closure(q2)
= {q2}
δ'(q2, 0) = ε-closure(δ(ε-closure(q2),0))
= ε-closure(δ(q2), 0))
= ε-closure(δ(q2, 0))
= ε-closure(Φ)
=Φ
δ'(q2, 1) = ε-closure(δ(ε-closure(q2),1))
= ε-closure(δ(q2), 1)
= ε-closure(δ(q2, 1))
= ε-closure(Φ)
=Φ
δ'(q2, 2) = ε-closure(δ(ε-closure(q2),2))
= ε-closure(δ({q2}, 2))
= ε-closure(δ(q2, 2))
= ε-closure(q2)
= {q2}
Now, we will summarize all the computed δ' transitions as given below:
δ'(q0,0)={q0,q1,q2}
δ'(q0,1)={q1,q2}
δ'(q0,2)={q2}
δ'(q1,0)= { Φ }
δ'(q1,1)={q1,q2}
δ'(q1,2)={q2}
δ'(q2,0)={ Φ }
δ'(q2,1)={ Φ }
δ'(q2,2)={q2}
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 36
III B.Tech AID R20 ATCD-UNIT-1
States\inputs 0 1 2
q1 Φ {q1,q2} {q2}
q2 Φ Φ {q2}
Note:
The presence of ε-transitions adds more flexibility in state transitions compared to a
regular NFA.
The ε-NFA provides a flexible way of designing automata by allowing transitions on ε,
enabling non-deterministic computation paths. By strategically placing ε-transitions,
you can simplify the design of complex automata and capture a broader range of
languages.
Moore and Mealy machines
(Finite Automata with output)
An FA that accepts input strings and translates them into output strings is
called FA with outputs.
Both Moore and Mealy machines are special case of DFA.
Both acts like output producers rather than language acceptors
In both no need to define final state
In both no concept of dead state
Both are equivalent in power
Moore machine is created by E.F.Moore in 1956 and Mealy machine is
created by G.H.Mealy in 1955
Moore Machine:
Moore machine is a FA whose outputs depend on only the present state.
The output is associated with the state i.e. Output is placed on state.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 37
III B.Tech AID R20 ATCD-UNIT-1
The output at a given time depends only upon the present state of the
machine
On input it gives output (q0) i.e. output of starting state.
i.e. It responses for empty string
If the input string is of length n, the output string is of length n+1
A Moore machine can be described by a 6-tuple (Q, ∑, ∆, δ, , q0) where
Q is a finite set of states.
∑ is a finite set of symbols called the input alphabet.
∆ is a finite set of symbols called the output alphabet.
δ is the input transition function where δ: Q × ∑ → Q
is the output transition function where : Q → ∆
q0 is the initial state from where any input is processed (q0 ∈ Q).
Example: The state diagram of the Moore Machine :
q0 q1 q0 0
q1 q2 q0 0
q2 q2 q3 0
q3 q1 q0 1
Mealy Machine
A Mealy Machine is a FA whose output depends on the present state as
well as the present input.
The output is associated with the transition i.e. Output is placed on
transition.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 38
III B.Tech AID R20 ATCD-UNIT-1
The output at a given time is function of the present input as well as the
present state of the machine
On input it gives output i.e. It does not responses for empty string
If the input string is of length n, the output string is also of length n
It can be described by a 6-tuple (Q, ∑, ∆, δ, X, q0) where
Q is a finite, non-empty set of states.
∑ is a finite, non-empty set of symbols called the input alphabet.
∆ is a finite, non-empty set of symbols called the output alphabet.
δ is the transition function where δ: Q × ∑ → Q
is the output function where : Q × ∑ → ∆
q0 is the initial state from where any input is processed (q0 ∈ Q).
The state Diagram of a Mealy Machine is shown below :
Next state
q0 q1 0 q3 0
q1 q3 1 q2 1
q2 q3 0 q3 1
q3 q3 1 q0 1
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 39
III B.Tech AID R20 ATCD-UNIT-1
Problem: Design a Mealy machine for a binary input sequence such that if it
has a substring 101, the machine output A, if the input has substring 110, it
outputs B otherwise it outputs C.
The output is associated with the state The output is associated with the transition
i.e. Output is placed on state. i.e. Output is placed on transition.
The output at a given time depends only upon The output at a given time is function of the present input
the present state of the machine as well as the present state of the machine
The output function maps from Q to ∆ The output function maps from Q×∑ to ∆
If the input string is of length n, the output If the input string is of length n, the output string is also of
string is of length n+1 length n
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 40
III B.Tech AID R20 ATCD-UNIT-1
Tutorial Questions:
1. Why do we need to study automata theory and formal languages?
2. What is DFA? Find the DFA for the following languages over {0, 1}*
i) The set of all strings such that number of 0’s is odd
ii) The set of all strings that contain exactly three 1’s
iii) The set of all strings that do not contain 1101
3. Design DFA which accepts language L={0,000,00000…….} over {0}
4. Design a DFA L(M) = {w | w ε {0, 1}*} and W is a string that does not contain
three consecutive 1's.Process the string 0011001 on machine.
5. Design DFA to accept strings with ‘c’ and ‘d’ such that number of d’s are
divisible by 4.Show the moves of DFA for the string cdcddcd
6. Design a DFA to accept the language:
L = {w |w has both an even number of 0’s and an even number of 1’s}.
Represent obtained DFA by transition table. Show the transitions of DFA for
the string 110101.
7. What is DFA? Find the DFA’s accepting for the following languages over the
alphabet {a,b,c}:
i) The set of all strings with abc as a substring
ii) The set of all strings ending in bac
iii) The set of all strings starting with cab
8. Draw a deterministic and non-deterministic finite automata for ∑= {A-Z}
which accept a string containing “CSE” at the end of a string of {A-Z}.
9. Design DFA for the following over {a,b}.
i) All string containing not more than three a’s.
ii) All strings that has at least two occurrences of b between any two occurrences
of a.
iii) All strings ending with aa
10. Construct a DFA for set of strings containing either the substring ‘aaa’ or
‘bbb’.
11. Construct a DFA for accepting a set of strings over Σ = {0, 1} not ending in
‘010’.
12. Design the DFA for the language, containing strings in which leftmost symbol differ
from rightmost symbol. Σ = {0, 1}
13. What is DFA? Construct a DFA accepting the language
{ W {a,b}*| W has neither aa nor bb as substring}
14. Draw the DFA for the following
i) To accept decimal strings divisible by 3 over the alphabet ∑={0,1,2,3,4,5,6,7,8,9}
ii) To accept odd number of a’s and even number of b’s over alphabet ∑ = {a,b}
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 41
III B.Tech AID R20 ATCD-UNIT-1
15. Design a DFA that reads strings made up of letters in the word ‘CHARIOT’ and
recognizes these strings that contain the word ‘CAT’ as a substring.
16. Define Deterministic and Non-deterministic finite automaton.
17. Differentiate between NFA and DFA?
18. Design an NFA with Σ = {0, 1} accepts all string in which the third symbol from
the right end is always 0.
19. Construct an NFA that accepts the set of all strings over {0,1} that start with 0
or 1 and end with 10 or 01.
20. Design a NFA for the following language L={0101n where n>0}
21. Describe the procedure of converting NFA to DFA with a suitable example.
22. Convert the given NFA to equivalent DFA
28. Explain the procedure for constructing minimum state DFA with an example.
(OR) What is minimal DFA? Write the minimization Algorithm for DFA?
29. Let ∑= {a, b}, Give DFA that accepts any string with aababb as a substring.
Minimize the DFA obtained.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 42
III B.Tech AID R20 ATCD-UNIT-1
30. Reduce the following DFA where q1 is the start state and q6 is the final state.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 43
III B.Tech AID R20 ATCD-UNIT-1
36. Bring out the differences between Moore and Mealy machines?
37. Design a Moore machine with the input alphabet {0, 1} and output alphabet
{Y, N} which produces Y as output if input sequence contains 1010 as a
substring otherwise, it produces N as output.
38. Design a mealy machine to print out 1’s complement of an input bit string?
39. Design a Moore machine for 2’s complement of binary number.
40. Construct the Moore machine to compute residue modulo 5 and finds to its
equivalent Mealy machine.
41. Draw a Moore machine for calculating mod 3 of a given binary number. Find
its equivalent mealy machine.
42. Construct a Moore machine that determines whether an input string contains
an even or odd number of 1's. The machine should give 1 as output if an even
number of 1’s is in the string and 0 otherwise.
43. Design a Moore and Mealy machines for a binary input sequence such that if
it has a substring 101, the machine outputs A, if the input has substring 110, it
outputs B otherwise it outputs C.
44. Design a Moore and Mealy machine that scans sequence of input of 0 and 1
and generates output 'A' if the input string terminates in 00, output 'B' if the
string terminates in 11, and output 'C' otherwise.
45. Design Moore and Mealy Machine to increment binary number by 1
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 44
III B.Tech AID R20 ATCD-UNIT-1
46. Give Mealy and Moore machine for the following: For input from ∑*, where ∑=
{0,1,2}, print the residue modulo 5 of the input treated as a ternary (base 3,
with digits 0, 1 and 2) number.
47. Design a Moore Machine that will read sequences made up of letters a, e, i, o,
u and will give as output, same characters except when an ‘i’ is followed by ‘e’,
it will be changed to ‘u’.
48. Design a Mealy machine to add two binary numbers of the form x1x2…xk,
y1y2…yk?
49. Convert the following Mealy machine to an equivalent Moore machine
50. Convert the following Mealy machine into equivalent Moore machine.
Prepared By: MD SHAKEEL AHMED, Associate Professor, Dept. Of IT, VVIT, Guntur Page 45