Académique Documents
Professionnel Documents
Culture Documents
Hierarchy, Computation, Finite State Machines (FSM): Deterministic FSM, Regular languages,
Designing FSM, Nondeterministic FSMs, From FSMs to Operational Systems, Simulators for FSMs,
Minimizing FSMs, Canonical form of Regular languages, Finite State Transducers, Bidirectional
Transducers.
Module 1
CONTENTS
Chapter No. Title Page No.
1 INTRODUCTION 1 - 16
INTRODUCTION
Why Study the Theory of Computation
Why do we need to study Automata Theory (Theory of Computation)?
Theory of computation lays a strong foundation for a lot of abstract areas of computer science. TOC
teaches you about the elementary ways in which a computer can be made to think. Implementations
come and go, but today's programmers can't read code from 50 years ago. Programmers from the
early days could never have imagined what a program of today would look like. In the face of that
kind of change, TOC is very important to study the mathematical properties, of problems and of
algorithms for solving problems that depend on neither the details of today's technology nor the
programming fashion of early days. It is desirable to know which problem can be algorithmically
solved and which cannot. Understanding which problems can be algorithmically solved is one of the
main objectives of theory of computation.
TOC provides a set of abstract structures that are useful for solving certain classes of
problems. These abstract structures can be implemented on whatever hardware/software
platform is available.
Using these abstract structures the required design efforts can be determined for the actual
model.
Using TOC, problems are analyzed by finding the fundamental properties of the problems
themselves such as:
1. Is there any computational solution to the problem? 1f not, is there a restricted
but useful variation of the problem for which a solution does exist.
2. If a solution exists, can it be implemented using some fixed amount of
memory'?
3. If a solution exists, how efficient is it? More specifically, how do its time and
space requirements grow as the size of the problem grows'?
4. Are there groups of problems that are equivalent in the sense that if there is an
efficient solution to one member of the group there is an efficient solution to
all the others'?
TOC plays an important role in compiler design, in switching theory, design and analysis of
digital circuits, etc.
i. Automata is required for designing software and checking the behavior of digital circuits
ii. Software for verifying systems of all types that have finite number of distinct states.
iii. Structural representation of automata like grammars and regular expressions are very
useful in designing of software for lexical analyzer of typical compiler.
iv. In designing of software for identifying the words, phrases and other patterns in large bodies
of text such as collection of web pages.
v. Computational Biology: DNA & proteins are strings.
vi. In artificial intelligence and knowledge engineering, game theory and computer graphics.
vii. Automata are essential for the study of the limits of computation like
a. What can a computer do at all? (Decidability)
b. What can a computer do efficiently?(Intractability)
2. Strings: A string is a finite sequence, possibly empty, of symbols chosen from some alphabet Σ.
Example: ε , 0, 1, 01, 10, 11, 110, 01110 … is the strings from the binary alphabet, Σ = {0, 1}
NOTE: 1. Given any alphabet Σ, the shortest string that can be formed from Σ is the empty string,
which we will write as ε.
*
2. The set of all possible strings over an alphabet Σ is written as Σ .
*
3. Σ notation exploits the Kleene Star operator.
4. Length of a string: The length of a string‘s’, is the number of symbols or characters in‘s’.
|10010| = 5
NOTE: For any symbol ‘c’ and string ‘s’, we define the function #c(s) to be the number of times
that the symbol ‘c’ occurs in string ’s’. So, for example, #a(abbaaa) = 4
5. Concatenation of strings: Concatenation of two strings ‘s’ and ‘t’ is the string formed by
appending the string ‘t’ to string ‘s’.
It is denoted by: s||t or st
Example: If the string s = good and the string t = bye then st = goodbye.
NOTE: 1. |xy| = |x| + |y|
2. The empty string, ε, is the identity for concatenation of strings. (So for all x (x ε = ε x = x)
3. Concatenation, as a function defined on strings, is associative. So for all s, t, w ((st)w =
s(tw)).
6. Replication: For each string w and each natural number k, the string w; is defined as:
w0 = ε
wk+1 = wk w
For example: a3 = aaa
(bye)2 = byebye
a2b3 = aabbb
7. Reversal of a string: The reversal of a string w is obtained by writing the symbols in reverse
order, which is denoted by wR
Example: w = 11001 wR = 10011
NOTE: 1. If |w| = 0 then wR = w = ε
2. If |w| ≥ 1 then a € ∑( u €∑*( w=ua) (i.e., the last character of w is a.) then wR =auR
3. If w and x are strings then (wx)R = xR wR
Relations on Strings
8. Substring: A string‘s’ is a substring of a string ‘t’ if ‘s’ occurs contiguously as part of ‘t’.
Example: aaa is a substring of string aaabbbaaa
aaaaaa is not a substring of string aaabbbaaa
9. Proper Substring: A string ‘s’ is a proper substring of a string ‘t’ if ‘s’ is a substring of ‘t’ and
s≠t
Example: aaabbbaaa is not a proper substring of string aaabbbaaa
10. Prefix of a string: Prefix is a string of any number of leading symbols. A string ‘s’ is a prefix of
‘t’ if x € ∑* (t = sx)
Example: Prefixes of a string abba are: ε , a, ab, abb, abba.
11. Proper Prefix: A string ‘s’ is a proper prefix of a string ‘t’ if ‘s’ is a prefix of ‘t’ and s ≠ t.
Example: Proper prefixes of a string abba are: ε , a, ab, abb ( where abba is not a proper prefix)
NOTE: 1. Every string is (although not a proper prefix) a prefix of itself.
2. The empty string ε is a prefix of every string.
12. Suffix of a string: Suffix is a string of any number of trailing symbols. A string ‘s’ is a suffix of
‘t’ if x € ∑* (t = xs)
Example: Suffixes of a string abba are: ε , a, ba, bba, abba.
13. Proper Suffix: A string ‘s’ is a proper suffix of a string ‘t’ if ‘s’ is a suffix of ‘t’ and s ≠ t.
Example: Proper suffixes of a string abba are: ε , a, ba, bba( where abba is not a proper suffix)
NOTE: 1. Every string is (although not a proper suffix) a suffix of itself.
2. The empty string ε is a suffix of every string.
14. Language: A language is a (Finite or Infinite) set of all strings, which are chosen from some Σ*,
where Σ is a particular finite alphabet.
Example: ∑ = {a, b}
∑* = { ε, a, b, aa, ab, ba, bb, aaa, aab,………………..}
Suppose Language contains set of all strings of a’s and b’s with an equal number of each is given
by: L ={ ε, ab, ba, aabb,baab, baba,……………………….}
15 Powers of an alphabet : Power of an alphabet is the set of strings of certain length (k) obtained
from an alphabet Σ. It is denoted by Σk
Example: If Σ = {0,1}, then Σ0 ={ ε }, Σ1 = { 0, 1}, Σ2 = { 00,01,10,11}, Σ2 = { 000, 001,
010,011,100,101,110,111} and so on.
The set of languages defined on ∑ is P( ∑*), the power set of ∑* or the set of all subsets of ∑*. If ∑ =
Ø then ∑* is { ϵ} and P(∑*), is {Ø, { ϵ} }.
NOTE: 1. L= { } = Φ is the empty language, is a language over any alphabet.
2. L= {ε} the language consisting of only the empty string, is also a language over any
alphabet.
Example: 1 Language contains strings of a’s and b’s with all a's precede all b's can be defined as:
L = { w € (a, b)* | All a’s precede all b’s in w}
The strings which are defined in the language L are:
L { ε, a, b, aa, ab, bb,aabbb…………………….}
The strings aba, ba, and abc are not defined in the language L.
Rules: For the above language all it says that any a's there are must come before all the b's (if any).
If there are no a's or no b's, then there can be none that violate the rule. So the strings ε, a, aa, and bb
trivially satisfy the rule and are in L.
Example 2: Let L = {x : y€ {a, b}* (x = ya)}. Give an English description of the language.
L { a, aa, ba, aaa, baa, bbaa……..}.
Language L contains strings of a’s and b’s ending with ‘a’.
Note: ( a, b) * means all strings can be formed by concatenating the symbols a and b zero or more
times
Example 3: Let L = {x # y : x, y € {0,1, 2. 3. 4. 5. 6. 7, 8, 9}* and, when x and y are viewed as the
decimal representations of natural numbers, square(x) = y }.
The strings 3#9 and 12#144 are in L.
The strings 3#8 and 12#12#12 are not in L.
A Halting Problem language
Let L = {w | w is a C program that halts on all inputs}. L is substantially more complex than, for
example, {x e { a,b }*: all a's precede all b's}. But, unlike English, there does exist a clear formal
specification of it. The theory that we are about to build will tell us something very useful about L.
We can use the relations that we have defined on strings as a way to define languages.
Language examples using the Prefix Relation:
We define the following languages in terms of the prefix relation on strings:
L1 = {w € {a, b}* | no prefix of w contains b}
L1 = {ε , a, aa, aaa, aaaa, aaaaa, aaaaaa, ... } .
L2 = { w €{a, b}*| no prefix of w starts with b}
L2 = { ε, a, ab, aa, abb, aaa, ………………….}
L3= {w € {a, b}*| every prefix of w starts with b}
L3 = Φ because ε is a prefix of every string.
Language examples using the replication notation:
Let L = { an : n ≥ 0 }
L = {ε, a, aa, aaa, aaaa, aaaaa, ... ……………..}
Problems:
Let = {a, b}
1. L = { w * : |w| < 3}
2. L = { w * | w begins with b}
3. L = { w * | #b(w) = 2}
4. L = { w * | each a is followed by exactly 2 b’s}
5. L = { w * | w does not begin with a}
6. L = {ba2n : n 0}
7. L = {bnan : n 0}
Answers:
1. L = { ε, a, b, aa, ab, ba, bb }
2. L = { b, ba, bb, baa, bab, bba, bbb………… }
3. L = { bb, abb, aabb, bab, baba,……………..}
4. L = { abb, abbabb, abbabbabb,……………. }
5. L = { ε, b, ba, baa, bab, bba, bbb,…………. }
6. L = { b, baa, baaaa, baaaaaa,………………. }
7. L = { ε, ba, bbaa, bbbaaa, bbbbaaaa,..……. }
Computational definition of a language could be specified either by
A language generator, which enumerates (lists) the elements of the language, or
A language recognizer, which decides whether or not a candidate string is in the language
and returns True if it is and False if it isn't.
For example, the logical definition of L = {x: y € (a, b)* (x = ya) can he turned into either a
language generator (enumerator) or a language recognizer.
Enumeration:
When we consider an enumerator for a Language L; we may care about the order in which the
elements (strings) of L are generated.
We consider any a) Arbitrary order b) Lexicographic order; which is more useful
Lexicographic order of strings: The strings which is defined in the language L are ordered as:
Functions on languages
All the standard set operations such as Union, Intersection, Difference and Complement are well
defined on languages.
Example: Let ∑ = { a, b}
L1 = {Strings with even number of ‘a’ s }
L2 = {Strings no ‘b’ s }
Find a) L1 U L2 b) L1 ∩ L2 c) L2 – L1 d)
Answer:
L1 = { ε, b, bb, aab, aabb,………………..}
L2 = { ε, a, aa, aaa, aaaa………………….}
L1 U L2 = {all strings of just a's plus strings that contain b's and an even number of a's}.
L1 ∩ L2 = { Strings of all even number of a’s}
L2 – L1 = { Strings of all odd number of a’s }
= { Strings of any number of b’s with at least one b plus strings of even number of a’s}
The other 3 useful operations on languages are: Concatenation, Kleen-Star and Reverse.
Concatenation of Languages: Let L1 and L2 be two languages defined over some alphabet ∑.
Then their concatenation, written as L1L2 is:
L1L2 = {w € ∑* : s € L1 ( t € L2 (w = st)) }
Example 1:
Let: L1 = {cat, dog. mouse, bird}.
L2 = {bone, food}.
L1L2 = {catbone, catfood, dogbane. dogfood. mousebone, mousefood, birdbone, birdfood}.
The + operator (L+) :Let L be a language defined over some alphabet ∑. Then L+ is the language
consisting of concatenation of one or more strings from L.
Example: L { 0, 1}+ be the set of binary strings, where L does not include .
L+ = L L* L+ = L* - {} if does not belongs to L
Reverse of a Language: Let L be a language defined over some alphabet ∑. Then the reverse of L
LR is the set of strings that can be formed by taking some string in L and reversing it.
LR = { w € ∑* | w = xR for some x € L }
If L1 and L2 are languages then (L1L2)R = L2RL1R
Closure: A set S is closed under the operation @ if for every element x and y in S, ie: x@y is also
element of S.
Example: L = {a, b} is not closed under concatenation. Since the elements after concatenation does
not belongs to L.
Semantics: Assigning Meaning to Strings
Sometimes we are interested in viewing a language just as a set of strings. For example consider the
language with strings of the form anbn | ≥ 0. L is the language composed of all strings of a's and b's
such that all the a's come first and the number of a's equals the number of b's. We won't attempt to
assign meanings to any those strings. But some languages are useful precisely because their strings do
have meanings. For example, the meaning of a Java program can be described as a Java Virtual
Machine program. A semantic interpretation function assigns meanings to the strings of a language.
One significant property of semantic interpretation functions for useful languages is that they are
generally not one-to-one. Consider:
English: The sentences, "Chocolate, please," "I'd like chocolate," "I'll have chocolate," and "I
guess chocolate today," all mean the same thing, at least in the context of ordering an ice
cream cone.
Java: The following chunks of code all do the same thing:
int x -= 4; x++;
int x - 4; ++x:
int x = 4; x = x + 1;
int x - 4; x = x --1; These all have the same result/meaning.
No. Every string in L must have the same number of 1’s as 2’s.
2 Let L1 = {anbn: n > 0}. Let L2 = {cn: n > 0}. For each of the following strings, state
whether or not it is an element of L1L2:
a) ϵ. No.
b) aabbcc. Yes.
c) abbcc. No.
d) aabbcccc. Yes.
3 Let L1 = {peach, apple, cherry} and L2 = {pie, cobbler, ɛ}. List the elements of L1L2
in lexicographic order.
L1L2 = {apple, peach, cherry, applepie, peachpie, cherrypie, applecobbler,
peachcobbler, cherrycobbler}
4 Let L = {w € {a, b}*: }. List the first six elements in a lexicographic
enumeration of L.
L = {ε, aaa, aab, aba, abb, baa……………}
5 For each of the following languages L, give a simple English description. Show two
strings that are in L and two that are not L.
7 For each of the following statements, state whether it is True or False. Prove your
answer.
a) Every infinite language is the complement of a finite language.
False. Counterexample: Given some nonempty alphabet ∑, the set of all even length
strings is an infinite language. Its complement is the set of all odd length strings,
which is also infinite.
b) L, (LR )R = L
True
L1, L2, ((L1 L2)* = L1* L2*)
c) False. Counterexample: L1 = {a}. L2 = {b}. (L1 L2)* = (ab)* and L1* L2* = a*b*.
L1, L2,( L1U L2)* = (L1* U L2*)
False. Counterexample: L1 = {a}. L2 = {b}. (L1 U L2)* = (a U b)*.
L1* U L2* = a* U b*.
d) L1, L2,( L1U L2)* = (L2 U L1)*
True
e)
Language Hierarchy
We need to build a frame work that lets us examine a new problem. The unifying framework that we
will use is language recognition. Assume that we are given:
The definition of a language L
A string w.
Then we must answer the question; “Is w in L?" This question is an instance of a more general class
that we will call decision problems.
Decision Problem: is simply a problem that requires a yes or no answer.
Computational Models: The First model is simple; programs written for it are generally easy to
understand, they run in linear time and algorithms exists to answer almost any question we might
wish to ask about such programs.. First model is less powerful. Second model is more powerful, but
still limited. The third model is powerful enough to describe anything that can be computed by any
sort of real computer. All these models will allow us to write programs, whose job is to accept some
language L.
The Chomsky’s hierarchy represents the class of languages that are accepted by different machine.
The category of languages in Chomsky’s hierarchy is as given below:
Write a short note on Chomsky’s Hierarchy
The four language classes are:.
1. Regular Language: This can be accepted by some Finite State Machine like DFSM or
NDFSM. FSM is the first computational model. Example: L = { Binary strings of even parity
} This language belongs to Type 3 language class. Regular languages are those languages
which can be described using regular expressions.
2. Context Free Language (CFL): which can be accepted by some Push Down Automata
(PDA). PDA is the second computational model. Example: L ={anbn | ≥ 0 } This language
belongs to Type 2 language class. Context Free languages are those languages which can be
represented by context free grammars.
3. Decidable Languages: This can be accepted by some Linear Bounded Automata, that always
halts. Example: L = { an bn cn | ≥ 0.}. Every decidable language is also semi decidable. } This
language belongs to Type 1 language class. Context sensitive grammars are used to represent
the language.
4. Semi decidable Language: This can be semi decided by some Turing Machine that halts on
all strings in the language. This language belongs to Type 0 language class.
Example: L = {n! }
A FSM is said to be deterministic if there is always exactly one move that can be made at each step.
That move is determined by the current state and the next input character, ie: for each input symbol
one transition is defined.
Define DFSM or DFA.
A Deterministic Finite State Machine (DFSM) ‘M’ is quintuple; M = ( K, ∑, δ, S, A ) where
K: is finite set of states.
∑ : is the input alphabet.
S € K is the start state.
A : is the subset of K, which is the set of all accepting (final) states.
δ: is the transition function, which maps from K X ∑ to K
Answer:
Language contains a minimum string as single a and there is no restrictions on b
L = { a, ab, ba, aa, aab………………………….}
So DFSM corresponding to this minimum string a is
Identify the transitions in each state which are not defined in the above DFSM.
In q0 for b input transition is not defined, q1 for a and b input transition is not defined,
In q0, on input b, it goes to q0, since any number of b’s followed by a is accepted by q0 (ie ba,
bba,bbba……), So before the suffix a, machine is in q0 and current state is also q0. Take self loop in
q0 on input b. δ( q0, b ) = qo).
To reach q1 state from q0, we need one input a, again in state q1 define a input a. So the string aa or
a followed by any number of a’s is accepted by q1 ie: δ( q1, a ) = q1
There is no restriction on b, so any number of b’s can be accepted by q1.δ( q1, b) = q1
Therefore the DFSM (DFA) for the above problem is given by M = ( { q0, q1 }, { a,b}, δ, q0, {q1} )
OR
δ is given by the transition table: ∑
state a b
q0 q1 q0
q1 q1 q1
NOTE: If any language contains ‘’ then make start state as final state.
Draw a DFSM (DFA) to accept the language contains strings of a’s and b’s having exactly one a.
There is no restriction on number of b’s, thus L contains only strings of one a and any no. of ‘b’ s.
Therefore the DFSM( DFA) for the above problem is given by M = ( { q0, q1, d }, {a, b}, δ, q0, {q1} )
Therefore the DFA for the given problem is M = ({ q0, q1,q2,q3}, { a, b}, δ, q0, {q3} )
Where δ is as shown in transition diagram.
All Strings of a’s and b’s except those which end with abb. ( not ending with abb)
Solution is similar to that of previous problem, except, consider non final states of previous problem
as a final state and final state as a non final state.
The DFSM for the problem which is not ending with abb is M = ( { q0, q1,q2,q3 }, { a, b}, δ, q0, {q0,
q1, q2}) and δ is as shown in transition diagram:
Minimum string in L is aab, so the DFSM (DFA) for the minimum string is:
Obtain a DFSM (DFA) to accept the language L contains strings of a’s and b’s except those having
substring aab.
Note: DFA construction procedure is same as that of previous problem except, make final state as
non final and non final state as final state of previous problem.
DFA M = ({ q0, q1,q2,q3 }, { a, b}, δ, q0, {q0, q1, q2} )
Where δ is as shown in transition diagram.
OR
Obtain a DFSM (DFA) to accept the language L contains strings of a’s and b’s starting with ab.
In state q0 on input b and in q1 on input a, machine enters trap state or a dead state Also ab followed
by any number of a’s and b’s is in q2 state is accepted.
DFSM (DFA) M = ( { q0, q1, q2, d }, { a, b}, δ, q0, {q2} )
Where δ is as shown in transition diagram.
Obtain a DFSM (DFA) to accept the language contains strings of 0’s and 1’s having three
consecutive 0’s.
Minimum string is 000 and its DFA is :
Draw a DFSM (DFA) to accept strings of a’s and b’s such that L = { awa | w € (a+b)* }
OR
Show that the language L = { awa | w € (a+b)* } is regular.
A language is regular if it is accepted by a DFA.
The minimum string for the language L = { awa } is aa, and its DFA is
Draw a DFA(DFSM) to accept strings of a’s and b’s such that L = { w (ab + ba) | w € (a+b)* }
OR
Dept of CSE Page 24
Automata Theory and Computability Finite State Machine- DFSM
Draw a DFA(DFSM) to accept strings of a’s and b’s ending with ab or ba.
Minimum string is ab or ba, and its DFSM is
Draw a DFSM to accept strings of 0’s, 1’s and 2’s beginning with a 0 followed by odd number of 1’s
and ending with a 2.
Minimum string is 012 and its DFSM (DFA):
DFA M = ({ q0, q1, q2, q3, d}, { 0, 1,2}, δ, q0, {q3}) where d is the trap state or dead state and δ is as
shown in transition diagram.
Draw a DFSM (DFA) to accept strings of a’s and b’s with at most two consecutive b’s.
Minimum string is bb and its DFSM (DFA) is
DFSM(DFA) M = ({ q0, q1, q2, d}, { a, b}, δ, q0, {q2 }) where d is the dead state and δ is as shown
in transition diagram:
Draw a DFSM (DFA) to accept strings of 0’s and 1’s , starting with at least two 0’s and ending with
at least two 1’s:
The DFSM (DFA) M = ({ q0, q1, q2, q3, q4, d}, { 0, 1}, δ, q0, {q4}) where d is the dead state and δ is
as shown in transition diagram:
Draw a DFSM (DFA) to accept strings of a’s and b’s having not more than three a’s.
OR
Draw a DFSM (DFA) to accept the Language L= { Na(w) <= 3, w € (a, b)* }
OR
Draw a DFSM (DFA) to accept the Language L= { #a(w) <= 3, w € (a, b)* }
Minimum strings are: ϵ, a, aa, aaa
The DFA M = ({ q0, q1, q2, q3, d}, { a, b}, δ, q0, {q0, q1, q2, q3}) where d is the dead state and δ is as
shown in transition diagram:
i. DFSM(DFA) to accept the strings of a’s and b’s starting with ab can be written as shown
below:
DFSM to accept the strings of a’s and b’s ending with ab can be written as shown below:
The two DFSM’s can be joined to accept the strings of a’s and b’s beginning with ab or ending
with ab or both can be written as shown below:
The DFSM M = ({ q0, q1, q2, q3, q4, q5}, { a, b}, δ, q0, {q2,q5,}) where δ is as
shown in transition diagram:
i. The set of strings with at least one “a” and exactly two ‘b’s.
The minimum strings may be abb or bab or bba and its DFA is as shown below:
Therefore the DFA M = ({ q0, q1, q2, q3, q4, q5,d}, { a, b}, δ, q0, {q3,}) and d is the trap state or dead
where δ is as shown in transition diagram
Obtain a DFSM(DFA) to accept the language contains strings of 0’s and 1’s with odd number of 1’s
followed by even number of 0’s.
The DFA M = ({ q0, q1, q2, q3, d}, { 0, 1}, δ, q0, {q1,q3 }) where δ is as shown in transition diagram:
Obtain a DFA to accept the language L = { w | w is of even length and begins with 01 }
The DFA M = ({ q0, q1, q2, q3, d}, { 0, 1}, δ, q0, {q2}) where δ is as shown in transition diagram:
Obtain a DFA to accept the language contains strings of binary odd numbers.
The DFA M = ({ q0, q1}, { 0, 1}, δ, q0, {q1}) where δ is as shown in transition diagram
Obtain a DFA to accept the set of all strings when interpreted as binary integer is an odd or even
number.
The DFSM M = ({ q0, q1, q2}, { 0, 1}, δ, q0, {q1,q2}) where δ is as shown in transition diagram
Design a DFSM for L = {w €{a. b}* : no two consecutive characters are the same}.
L = { ϵ, a, b, ab, ba, aba, bab,abab,……………}
The DFSM M = ({ q0, q1,q2, d}, { a, b}, δ, q0, {q0, q1, q2}) where δ is as shown in transition diagram.
Note: we have used the shorthand d to stand for any one of the decimal digits (0 - 9). And we have
omitted the dead state to avoid arrows crossing over each other.
Design a DFSM for L = {w € {a - z}*: all five vowels, a, e, i, o, and u, occur in w in alphabetical
order}.
So L contains words like abstemious, facetious, etc. But it does not contain tenacious, which does
contain all the vowels, but not in the correct order.
Let us consider the input symbol: ∑ - {a}, which means all elements of ∑ except {a}
∑ - {e} which means all elements of ∑ except {e}
∑ - {i}, which means all elements of ∑ except {i}
∑ - {o}, which means all elements of ∑ except {o}
∑ - {u}, which means all elements of ∑ except {u}
The DFSM M = ({ q0, q1,q2, q3, q4,q5 }, ∑ - {a}, ∑ - {e}, ∑ - {i}, ∑ - {o}, ∑ - {u}, a, e, i, o, u}, δ, q0,
{q5}) where δ is as shown in transition diagram:
--------------------------------------------------------------------------------------------------------
Modulo-n-problems: ( OR mod n )
Obtain a DFSM(DFA) to accept the language L = { |w| mod 3 = 0, where w € (a, b)* }
Mod 3 results in three remainders as 0, 1, 2. So in q0 state, no input symbol required to reach that
state, length is 0. Therefore q0 is identified as remainder 0 state. Similarly in q1 (length1), remainder
is 1, and q2 remainder is 2 (length 2). Afterwards it enters to q0 and the same process is repeated.
Final state is q0.
The DFSM (DFA) M = ({ q0, q1, q2}, { a, b}, δ, q0, {q0}) where δ is as shown in transition
diagram:
Obtain a DFSM (DFA) to accept the language L = { |w| < > 0, where w € (a, b)* }.
Obtain a DFSM ( DFA) to accept the language L = { w: |w| mod 5 = 0 } and w € (a,b)*
The possible strings in L ={ ε, ababb, aaaaa, bbbbb, baaab, ………….. }
Possible remainders are 0,1,2,3, 4. So there are 5 states, remainder 0 in start state and also the final
state.
The DFA M = ({ q0, q1, q2, q3, q4}, { a, b}, δ, q0, {q0}) where δ is as shown in transition
diagram
Obtain a DFSM (DFA) to accept the language L = { w: |w| mod 5 < > 0 } and w € (a, b)*
The DFA M = ({ q0, q1, q2, q3, q4}, { a, b}, δ, q0, { q1, q2, q3, q4}) where δ is as shown in
transition diagram
Obtain a DFSM (DFA) to accept the language L = { w: |w| mod 3 |w| mod 2 and w € (a,b)*}
Here mod 3 results in three reminders 0,1,2 and mod 2 results two remainders 0,1.
Let us consider |w| mod 3 = x and it results in three states say K1 = { 0, 1, 2 }
|w| mod 3 = y and it results in two states say K2 = { 0, 1 }.
Therefore the possible states for the given DFSM can be obtained by taking cross product of K 1 and
K2.
K = K1 X K2
K = {( 0, 0), ( 0, 1), (1, 0), (1, 1), (2, 0), (2, 1) }.
Here (0, 0) state is considered as start state.
Final state: To accept strings of w such that |w| mod 3 |w| mod 2 , is the pairs (x, y) such that x
y are final states.
So the final states are { (0,0), (1,0), (1,1), (2,0),(2,1) }
The DFA M = ({ q0, q1, q2, q3, q4, q5}, { a, b}, δ, q0, { q0, q1, q2, q4, q5}) where δ is as shown in
transition diagram
Obtain a DFSM (DFA) to accept the language L = { w: |w| mod 3 |w| mod 2 and w € (a, b)*}
Same as previous problem except the final state of DFA.
K1 = { 0, 1, 2 }
K2 = { 0, 1 }.
K = {( 0, 0), ( 0, 1), (1, 0), (1, 1), (2, 0), (2, 1) }.
Here (0, 0) state is considered as start state.
Final states are; x y ie: = { (0, 0), (0,1), (1,1) }
The DFSM M = ({ q0, q1, q2, q3, q4, q5}, { a, b}, δ, q0, { q0, q1, q3}) where δ is as shown in
transition diagram:
Obtain a DFSM (DFA) to accept the language L = { w: |w| mod 3 ≠ |w| mod 2 and w € (a,b)*}
Same as previous problem except the final state of DFA.
K = {( 0, 0), ( 0, 1), (1, 0), (1, 1), (2, 0), (2, 1) }.
Here (0, 0) state is considered as start state.
Final states are; x ≠ y ie: = { (0, 1), (1,0), (2,0), (2,1) }
The DFSM M = ({ q0, q1, q2, q3, q4, q5}, { a, b}, δ, q0, { q2, q3, q4, q5}) where δ is as shown in
transition diagram:
Obtain a DFSM(DFA) to accept the language L = { w | w € (a,b)*; #a(w) mod 3 = 2 and #b(w)
mod 2 =1 }
#a(w) mod 3 or Na(w) mod 3 results in remainders as 0,1,2 and the states corresponding to these
remainders can be represented as: K1 = { A0, A1, A2 }
#b(w) mod 2 or Nb(w) mod 2 results in remainders as 0,1 and the states corresponding to these
remainders can be represented as: K2 = { B0, B1 }
Here (A0,B0 ) is the start state and the language contains strings of a’s and b’s such that Na(w) mod
3 = 2 and Nb(w) mod 2 =1, results in a final state ( A2,B1).
The DFSM M = ({ q0, q1, q2, q3, q4, q5}, { a, b}, δ, q0, { q5}) where δ is as shown in transition
diagram:
Obtain a DFSM (DFA) to accept the language L = { w | w € (a,b)*; Na(w) mod 3 1 and Nb(w)
mod 2 1 }
Same as previous problem except the final state.
Final states ={ (A1,B0), ( A1,B1), (A2,B0), (A2,B1) .
The DFA M = ({ q0, q1, q2, q3, q4, q5}, { a, b}, δ, q0, { q1, q2, q4, q5}) where δ is as shown in
transition diagram:
****Obtain a DFSM (DFA) to accept the language contains strings of a’s and b’s such that,
i. Set of all strings having even number of a’s and even number of b’s.
ii. Set of all strings having even number of a’s and odd number of b’s.
iii. Set of all strings having odd number of a’s and even number of b’s.
iv. Set of all strings having odd number of a’s and odd number of b’s.
Set of all strings having even number of a’s and even number of b’s.:
OR
Number of a’s divisible 2 and number of b’s divisible by 2
OR
Number of a’s multiple of 2 and number of b’s multiple of 2
Solution:
Even number of a’s is nothing but Na(w) mod 2 = 0
Even number of b’s is nothing but Nb(w) mod 2 = 0.
So the possible remainders in each case is 0, 1;
Q1 = { A0, A1}
Q2 = { B0, B1}. Therefore K = K1 X K2 = { (A0, B0) , (A0, B1), (A1, B0), (A1, B1) }
Start state: (A0, B0)
Final state to accept the language contains even number of a’s and even number of b’s is (A0,B0).
So the DFA M = ({ q0, q1, q2, q3 }, { a, b}, δ, q0, { q0}) where δ is as shown in transition
diagram:
ii. Set of all strings having even number of a’s and odd number of b’s.
Same as previous problem except final state. ie: (A0, B1)
Even number of a’s is nothing but Na(w) mod 2 = 0
Odd number of b’s is nothing but Nb(w) mod 2 = 1.
DFA M = ({ q0, q1, q2, q3 }, { a, b}, δ, q0, { q2}) where δ is as shown in transition diagram:
iii. Set of all strings having odd number of a’s and even number of b’s.
Same as previous problem except final state. ie: (A1, B0)
Odd number of a’s is nothing but Na(w) mod 2 = 1
Even number of b’s is nothing but Nb(w) mod 2 = 0.
Dept of CSE Page 41
Automata Theory and Computability Finite State Machine- DFSM
DFA M = ({q0, q1, q2, q3 }, { a, b}, δ, q0, { q1}) where δ is as shown in transition diagram
iv. Set of all strings having odd number of a’s and odd number of b’s.
Odd number of a’s is nothing but Na(w) mod 2 = 1
Odd number of b’s is nothing but Nb(w) mod 2 = 1.
Same as previous problem except final state. ie: (A1, B1)
DFA M = ({ q0, q1, q2, q3 }, { a, b}, δ, q0, { q3}) where δ is as shown in transition diagram:
δ (q0, 0 ) = q0;
δ (q0, 1 ) = q1
δ (q1, 0 ) = q2
δ (q1, 1 ) = q3
δ (q2, 0 ) = q4
δ (q2, 1 ) = q0 start state is q0 and
final state is also q0.
δ (q3, 0 ) = q1
δ (q3, 1 ) = q2
δ (q4, 0 ) = q3
δ (q4, 1 ) = q4
The DFA(DFSM) for the above problem is M =({ q0, q1, q2, q3, q4 }, { 0, 1}, δ, q0, { q0}) where δ
is as shown in transition diagram:
Design a DFA to accept the set of all strings beginning with a 1 that when interpreted as binary
integer is a multiple of 5. For example 101, 1010, 1111 etc are in the language and 0, 100, 0101,
111, 01111 etc are not.
Solution remains same as that of previous problem, but the number should always start with a 1.
If a binary number starts with a 0, that number should never be accepted and machine enters to trap
state on input 0. So let us rename the final state of previous problem as qf and have the new start
state q0 and from this state on input 1 machine enters into state q1, and the remaining procedure is
same as that of previous problem.
Therefore the DFA for the above problem is M =({ q0, q1, q2, q3, q4 }, { 0, 1}, δ, q0, { qf}) where
δ is as shown in transition diagram:
Design a DFSM (DFA) to accept the set of all strings that when interpreted in reverse as a binary
integer is divisible by 5. Examples of strings in the language are 0, 10011, 1001100 and 0101.
Solution remains same as that of previous first problem, But reverse the direction of all arrow marks
except the arrow labeled with start.
Therefore the DFA for the above problem is M =({ q0, q1, q2, q3, q4 }, { 0, 1}, δ, q0, { q0}) where
δ is as shown in transition diagram:
Design a DFSM (DFA) to accept the set of all strings which when interpreted as binary integer is a
multiple of 3.
δ (q0, 0 ) = q0
δ (q0, 1 ) = q1
δ (q1, 0 ) = q2
δ (q1, 1 ) = q0
δ (q2, 0 ) = q1
δ (q2, 1 ) = q2
The DFA for the above problem is M =({ q0, q1, q2 }, { 0, 1}, δ, q0, { q0}) where δ is as shown
in transition diagram:
Exercises
Show a DFSM to accept each of the following languages:
1. {w € {a, b}*: every a in w is immediately preceded and followed by b}.
3. {w € {0 - 9}*: w corresponds to the decimal encoding, without leading 0’s, of an odd natural
number }
6. {w € {0, 1}*: w has no more than one pair of 0’s and no more than one pair of consecutive l's}
The set of binary strings with at most one pair of consecutive 0’s and at most one pair of consecutive
1’s.
DFSM NFSM
DFSM can make exactly one move, for each NFSM has zero or more moves for each input
input symbol in Σ. symbol in Σ from every state of the automaton.
An NDFSM M may have one or more transitions
that are labeled ε
It is deterministic finite automaton, where the Non deterministic finite automaton where the
moves of the automaton can be predicted. moves of automaton cannot be predicted.
NFSM with ε- transitions, where automaton can
change the state without reading input.
Number of states are more compared to NFA and Number of states are less compared to DFA and
difficult to construct easier to construct
DFA cannot guess about its input NFDSM with ε-transitions enable machine M to
guess at the correct path before it actually sees
the input
lf a NDFSM M is in state q0 and the next input character is an a, then there are three moves that M
could make:
1. It can take ε-transition to q1 before it reads the next input character,
2. It can read the next input character and take the transition to q2, or
3. It can read the next input character and take the transition to q3
NDFSM (NFA) M =({ q0, q1, q2, q3, q4, q5, q6}, { a, b}, δ, q0, { q4, q5}) where δ is as shown in
transition diagram:
i. L = { ababn or aban | n 0 }
NFA for the above problem is M =({ q0, q1, q2, q3, q4,qf }, { a, b}, δ, q0, { qf,q4}) where δ is as
shown in transition diagram:
v. L = { awa | w € ( a,b)* }.
NFA for the above problem is M =({ q0, q1, qf}, { a, b}, δ, q0, { qf) where δ is as shown in
transition diagram:
Design a NDFSM (NFA) for L = {w € {a, b, c}*: x, y € {a, b, c}* (w = x abcabb y)}
L contains w where w must contain at least one occurrence of the substring abcabb
NDFSM (NFA) M = ({ q0, q1, q2, q3, q4, q5, q6}, { a, b,c}, δ, q0, { q6}) where δ is as shown in
transition diagram:
Design a NDFSM (NFA) for L ={w € {a, b}*: x, y € {a, b}* ((w = x abbaa y) V (w = x baba y)) }
L contains w where w must contain at least one occurrence of the substring abbaa or the substring
baba
NDFSM (NFA) M = ({ q0, q1, q2, q3, q4, q5, q6, q7, q8, q9}, { a, b}, δ, q0, { q5, q9}) where δ is as shown
in transition diagram:
Design a NDFSM (NFA) for L = { w €{a, b}*: the fourth character from the last character is a}.
NDFSM (NFA) M = ({ q0, q1, q2, q3, q4 }, { a, b}, δ, q0, { q4}) where δ is as shown in transition
diagram:
Handling ε -Transitions
What is epsilon-closure?
Epsilon closure of any state q is the set of all states which are reachable from state q on ε-transitions
only. ε-closure(q) is denoted by eps (q)
Algorithm to compute eps(q):
eps (q: state) =
1. result = {q }.
2. While there exists some state p € result and some state r does not belongs to result and
some transition (p, ε, r) € ∂ do: Insert r into result.
3. Return result.
Compute the epsilon closure of each state of the following automata.
2. s' = eps(s).
3. Compute ∂’:
a. active-states = { s'}.
b. ∂’ = Ø
While there exists some element Q of active-states for which ∂’ has not yet been computed do:
For each character a in ∑ do:
new-state = Ø.
For each state q in Q do:
ε a b c
→p {q, r} φ {q} {r}
q φ {p} {r} {p, q}
*r φ φ φ φ
For the given problem the equivalent Transition diagram of NDFSM is:
= eps{ Ø U p U Ø }
= eps{ p} = { p, q, r }
That is ∂’(({p, q, r}, a), {p, q, r}) ( This is already existing in active state, so no need to
add this state)
∂’({p, q, r}, b) = eps{∂(p, b) U ∂(q, b) U ∂( r, b) }
= eps{ q U r U Ø }
= eps({q, r}) = eps(q) U eps(r) = {q} U {r} = { q, r }
∂’(({p, q, r}, b), { q, r}) ( This state is not existing in active state, so we need to
add this state to Active state.)
= eps{ p U Ø }
= eps{ p} = { p, q, r }
∂’(({p, q, r}, a), {p, q, r}) existing state
∂’({q, r}, b)) = eps{∂(q, b) U ∂(r, b) }
= eps{ r U Ø }
= eps{ r} = { r }
∂’(({q, r}, b), { r}) new state ; add this state to Active state
∂’({q, r}, c)) = eps{∂(q, c) U ∂(r, c) }
= eps{{p, q} U Ø }
= eps({p, q}) =eps(p) U eps(q) = {p, q, r} U { q } = { p, q, r}
∂’(({q, r}, c), { p, q, r}) existing state
Active states = {{ p, q, r }, {q, r }, {r}}
Now define the transitions in state { r} on input ∑ = {a, b, c}
∂’(r, a) = eps(∂(r, a)) = eps (Ø) = Ø new state; this state is a dead state, we will generally omit
it.
∂’(r, b) = eps(∂(r, b)) = eps (Ø) = Ø
NOTE: Final states of DFSM is determined by identifying the final states of given NDFSM.
See the states of DFSM K’ and those states having the final states of NDFSM has its components
are considered as final states of DFSM or DFA,
The resultant DFSM or DFA :
δ ε a b
→p {r} {q} {p, r}
q φ {p} φ
*
r {p, q} {p}
r}
Also give the set of all strings of length 3 or less accepted by the automaton.
The equivalent Transition diagram of NDFSM is:
eps (q) = { q }
eps (r) = {p, q, r }
2 Start state of DFSM (DFA) s’ = eps (start state of NDFSM) = eps (p) = {p, q, r}
Eps closure:
Minimizing FSMs
If we are going to solve a real problem with an FSM. we may want to find the smallest one that does
the job. We will say that a DFSM M is minimal if there is no other DFSM M' such that L(M) = L(M')
and M' has fewer states than M does.
We might want to be able to ask:
1. Given a language, L, is there a minimal DFSM that accepts L?
2. If there is a minimal machine, is it unique?
3. Given a DFSM M that accepts some language, can we tell whether M is minimal?
4. Given a DFSM M. can we construct a minimal equivalent DFSM M'?
What are indistinguishable and distinguishable strings?
Indistinguishable strings: Two strings x and y are indistinguishable with respect to a language L,
which we will write as:
if
In other words if x and y are viewed as prefixes of some longer string, no matter what continuation
string z comes next, either both xz and yz are in L or both are not.
Distinguishable strings: Two strings x and y are distinguishable with respect to a language L, if
there exists at least one string z such that one but not both of xz and yz is in L.
is an equivalence relation since it is:
Determining .
Let ∑ = {a, b }. Let L = {w € (a, b)*: every a is immediately followed by a b}. Determine the
equivalence class of L
The equivalence classes of are:
[1] [ɛ, b, abb…………………..] [all strings in L]
(2] [a, abbba…………………..] [ all strings that end in a and have no
Athmaranjan K Dept of ISE Page 65
Automata Theory and Computability Minimizing FSMs
Determine the equivalence class for the language L. Let ∑ = {a, b}. Let L = {w €{a, b}*: no two
adjacent characters are the same}.
The equivalence classes of are:
[1] [ɛ]
(2] [a, aba, ababa……..] [all nonempty strings that end in a and have no identical
adjacent characters]
[3] [b, ab, bab, abab……] [all nonempty strings that end in b and have no identical
adjacent characters]
[4] [aa. abaa. ababb…….] [all strings that contain at least one pair of identical
adjacent characters
Consider the following FSM that accepts L: determine the equivalent states.
Minimize the following DFSM (DFA) using partioning the states of machine into equivalence
classes method (Equivalence Theorem).
Transition table:
State a b
A B D
*B C F
C B D
*D F E
E B D
F F F
Step 1: Identify the states of DFSM, which are not reachable from start state: All states are reachable
from start state for the given DFSM.
Step 2: Identify the 0 equivalent classes of states: Initially we have the two classes of states as:
[all non-final states] [ all final states]
0 equivalent classes of states: [A, C, E, F] [B, D]
Step 3: 1 equivalent states: In order to construct 1 equivalent state, we have to refer 0 equivalent
states. See all the states within the class are equivalent or not by referring the transition table.
For example to check whether A and C are 1 equivalent:
δ(A, a) = B and δ(C, a) = B ----------belongs to same class
δ(A, b) = D and δ(C, b) = D ----------- belongs to same class
So both A and C 1 are equivalent.
A and E
δ(A, a) = B and δ(E, a) = B ----------belongs to same class
δ(A, b) = D and δ(E, b) = D ----------- belongs to same class
So both A and E are 1 equivalent.
Since A and C ; A and E are 1 equivalent; so C and E are also 1 equivalent
A and F
δ(A, a) = B and δ(F, a) = F ----------belongs to different class
Therefore A and F are not 1 equivalent, so we have to split the class [A, C, E, F] of 0 equivalent state
into two classes [A, C, E] and [F] in 1 equivalent states.
B and D
δ(B, a) = C and δ(D, a) = F ----------belongs to same class
δ(B, b) = F and δ(D, b) = E ----------belongs to same class
B and D are 1 equivalent.
Minimized DFSM:
Step 1: Since state D is not reachable from start state, we can eliminate that state.
So the resultant transition table:
Transition Table:
a b
→*q1 q2 q4
q2 q3 q5
*q3 q2 q6
q4 q5 q1
q5 q6 q2
q6 q5 q3
Transition table:
c d
(q1, q4) (q1, q4) (q2, q5)
(q2, q5) (q3, q6) (q1, q4)
(q3, q6) (q2, q7) (q3, q6)
(q2, q7) (q3, q6) (q1, q4)
From the above transition table, note that we do not get one final state and other non-final state in a
pair. Hence we declare that two DFSM’s are equivalent.
c d
(q1, q4) (q1, q4) (q2, q5)
(q2, q5) (q3, q7) (q1, q6)
We will terminate the construction of transition table because we get a pair of states (q1, q6) in which
q1 is a final state and q6 is a non-final state. As per the rule the given two DFSMs are not equivalent.
So far we have used a finite state machine as language recognizers (DFSM or NDFSM).
A finite-state transducer (FST) is a finite-state machine with two memory tapes, an input tape and
an output tape. A FST will read a set of strings on the input tape and generates a set of relations on
the output tape. In analyzing a machine M is whether or not M ends in an accepting state. But it is a
simple matter to augment our finite state model to allow for output at each step of a machine's
operation.
One simple kind of finite state transducer associates an output with each state of a machine
M. That output is generated whenever M enters the associated state. Deterministic finite state
transducers of this sort are called Moore machines. A Moore machine, whose output values
are determined solely by its current state
Another deterministic finite state transducers Mealy machine, whose output values are
determined both by its current state and the current input.
MOORE MACHINE
Define Moore machine.
A Moore machine M is a seven-tuple (K, ∑, O, δ, D, s, A) where:
Construct a Moore machine for a binary input sequence such that if it has a substring 101 the
machine outputs A, if it has substring 110 it outputs B otherwise it outputs C
Initially, the partial design for the given problem is:
Now we will insert the possibilities of 0’s and 1’s for each state. Then the Moore machine becomes:
Design a Moore machine for computing the 2’s complement of binary number
In order to compute 2’s complement of a binary number, we assume that input is read from LSB to
MSB. We will keep the binary number as it is until we read first 1. Keep that 1 as it is and then
change remaining 1’s by 0’s and 0’s by 1’s.
Construct a Moore machine that takes set of all strings over {a, b} as input and print ‘1’ as output for
every occurrence of ‘abb’ as a substring.
Moore Machine:
∑ = { a, b} and O = {0, 1}
D = {A→0, B→0, C→0 and D→ 1} ( Every state has associated output)
Mealy machine, It is a deterministic machine, whose output values are determined both by its
current state and the current input.
Define Mealy machine
Mealy machine is a six tuple (K, ∑, O, δ, s, A) where:
Design a Mealy machine for computing the 2’s complement of binary number
Construct a Mealy machine for a binary input sequence such that if it has a substring 101 the
machine outputs A, if it has substring 110 it outputs B otherwise it outputs C
Construct a Mealy machine which adds an odd parity bit after every four binary digits that it reads.
∑ = { 0, 1} O = { 0, 1}
0 1 1 0
A → B → E → F → A
↓ ↓ ↓ ↓
0 1 1 01
Bidirectional Transducers
Dept CSE Page 82
Automata Theory and Computability
A process that reads an input string and constructs a corresponding output string can be described in
a variety of different ways. Why should we choose the finite state transducer model? One reason is
that it provides a declarative, rather than a procedural, way to describe the relationship between
inputs and outputs. Such a declarative model can then be run in two directions. ie: Left and right.
It can be a non-deterministic transducer, if the direction is not considered.
Example: The Soundex system designed in U.S. is a bidirectional transducer.
Many times in handling the database of people we find that people change the spellings of their
name. In such situations, finding the record for those people becomes difficult. Hence the code can
be attached to their names.
Soundex system is a system that addresses these issues. The system maps any name to a four
character code that is derived from the original name. So to find the related names, one can run the
soundex transducer in one direction from a starting name to its soundex code and then in the other
direction from the code to the other names that share that code.
We can build a simple bidirectional transducer that can convert strings in L to strings in L' and vice
versa. L defined over the alphabet {a, b} and L’ that contains exactly the strings in L except that
every a has been replaced by a 0 and every b has been replaced by a 1.