Vous êtes sur la page 1sur 85

AUTOMATA THEORY AND COMPUTABILITY

[As per Choice Based Credit System (CBCS) scheme]


(Effective from the academic year 2016 -2017)
SEMESTER – V
MODULE 1
Notes
Why study the Theory of Computation, Languages and Strings: Strings, Languages. A Language

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

1.1 Why Study the Theory of Computation 1


1.2 Languages and Strings 3
1.3 A Language Hierarchy, 14
1.4 Computation 16
2 FINITE STATE MACHINES (FSM) 17- 75

2.1 Deterministic FSM, Regular languages 17


2.2 Designing FSM 18
2.3 Nondeterministic FSMs 49
2.4 From FSMs to Operational Systems 63
2.5 Simulators for FSMs 64
2.6 Minimizing FSMs 65
2.7 Canonical form of Regular languages 75
3 FINITE STATE TRANSDUCERS 78 - 83

3.1 Bidirectional Transducers 83


Automata Theory and Computability Why Study the Theory of Computation

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.

Dept of CSE Page 1


Automata Theory and Computability Why Study the Theory of Computation

Applications of Automata Theory

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)

Dept of CSE Page 2


Automata Theory and Computability Languages and strings

Languages and Strings

Define the following terms with respect to automata theory


1. Alphabets: An alphabet is a finite non empty set of symbols or characters.
We use the symbol Σ for an alphabet.
Example: 1. Σ = {0, 1}, the binary alphabet
2. Σ = {a, b,………….z}, the English lower-case alphabets.

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.

3. Empty string: It is the string with zero occurrences of symbols or characters.

This string is denoted by ε , may be chosen from any alphabet whatsoever.

4. Length of a string: The length of a string‘s’, is the number of symbols or characters in‘s’.

It is denoted by: |s|


Example: | ε | = 0

|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|

Dept of CSE Page 3


Automata Theory and Computability Languages and strings

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

NOTE: 1. Every string is a substring (although not a proper substring) of itself.


2. The empty string ε is a substring of every string.

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.

Dept of CSE Page 4


Automata Theory and Computability Languages and strings

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.

Techniques for Defining Languages


We will use a variety of techniques for defining the languages that we wish to consider. Since
languages are sets, we can define them using any of the set-defining techniques as:
L = { w  * | description of w}

Dept of CSE Page 5


Automata Theory and Computability Languages and strings

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:

Dept of CSE Page 6


Automata Theory and Computability Languages and strings

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:

Dept of CSE Page 7


Automata Theory and Computability Languages and strings

 First write the shortest (minimum length) string.


 Strings that are the same length, are ordered in dictionary (alphabetical) order.
Example: Let L = {x € {a, b )*: all a's precede all b's }.
The lexicographic enumeration of L= { ε, a. b.aa. ab, bb.aaa. aab. abb.bbb.aaaa,aaab. ………..}
Cardinality of a Language
The smallest language over any alphabet is Φ whose cardinality is 0. The largest language over any
alphabet ∑ is ∑*
Suppose that ∑= Φ Then ∑* = { ε} and |∑*| = l.
NOTE: 1. If ∑ ≠ Φ then ∑* is countably infinite.
2. If ∑ ≠ Φ then the set of languages over ∑ is un-countably infinite.

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}.

Dept of CSE Page 8


Automata Theory and Computability Languages and strings

L2 = {bone, food}.
L1L2 = {catbone, catfood, dogbane. dogfood. mousebone, mousefood, birdbone, birdfood}.

NOTE: 1. {} is the identity for concatenation: L{} = {}L = L


2.  is a zero for concatenation: L=L=
3. Concatenation defined on languages, is associative. So, for all languages L1, L2, L3:
((L1L2 )L3 = L1 (L2L3))

Example 2: Let L1 = { an | n ≥ 0 } and L2 = { bn | n ≥ 0 } what is L1L2 = ?


L1 = { , a, aa, aaa, aaaa,……………………… }
L1 = { , b, bb, bbb, bbbb,…………………… }
L1L2 = { an bm | n, m ≥ 0 }
Note: For the above languages L1L2 ≠ { an bn | n ≥ 0 } since every string in { an bn | n ≥ 0 } must
have the same number of b's as a's.
Kleen Star: Let L be a language defined over some alphabet ∑. Then the Kleen star of L; written
as L* is the set of strings that can be formed by concatenating together zero or more strings from L.
L* = {} U {w € ∑* : k ≥ 1 ( w1,w2,w3,……..wk € L (w = w1,w2, w3,…..wk)) }
Example 1:
Let L = {dog, cat, fish}. Then:
L * = { . dog, cat, fish, dogdog, dog cat, ...........
fishdog, .. . , fishcatfish, fishdogfishcat ………………}
Example 2:
Let L = { w € {a. b} * : #a( w) is odd and #b( w) is even}.
L = { a, abb, abbbb,………………. aaa, aaabb, aaabbbb,……………}
L* ={a, aa, aaa, aaaa, …..abb, aabb, aabbbb……………….}
Therefore L * = { w € {a, b} * : #b ( w) is even}.
Note: For the above example, the constraint on the number of a's disappears in the description of L*
because strings in L* are formed by concatenating together any number of strings from L. If an odd
number of strings are concatenated together, the result will contain an odd number of a's. If an even
number are used, the result will contain an even number of a's.

Dept of CSE Page 9


Automata Theory and Computability Languages and strings

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.

1 Consider the language L = {1n2n : n > 0}. Is the string 122 in L?

Dept of CSE Page 10


Automata Theory and Computability Languages and strings

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.

a) L = {w € {a, b}*: exactly one prefix of w ends in a}.


L is the set of strings composed of zero or more b’s and a single a.
a, bba and bbab are in L.
bbb andaaa are not in L

b) L = {w € {a, b}*: all prefixes of w end in a}.


L = Ø since ε is a prefix of every string and it doesn’t end in a. So all strings are not
in L, including a and aa.
+
c) L = {w € {a, b}*: x € {a, b} (w = axa)}.
L is the set of strings over the alphabet {a, b} whose length is at least 3 and that start
and end with a.
aba, and aaa are in L.
ε, a, ab and aa are not in L
6 Are the following sets closed under the following operations? If not, what are their
respective closures?

Dept of CSE Page 11


Automata Theory and Computability Languages and strings

a) The language L= {a, b} under concatenation


Not closed. {w €{a, b}* : |w| > 0}
b) The odd length strings over the alphabet ∑ = {a, b} under Kleene star.
Not closed because, if two odd length strings are concatenated, the result is of even
length. The closure is the set of all strings drawn from the alphabet {a, b}.
c) L = {w € {a, b}*} under reverse.
Closed. L includes all strings of a’s and b’s, so, since reverse must also generate
strings of a’s and b’s, any resulting string must have been in the original set.
d) L = {w € {a, b}* : w ends in a} under concatenation
Closed.
e) L = {w € {a, b}*: w starts with a} under reverse.
Not closed. L includes strings that end in b. When such strings are reversed, they
start with b, so they are not in L. But, when any string in L is reversed, it ends in a.
So the closure is {w € {a, b}*: w starts with a} U {w €{a, b}* : w ends with a}.

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)

Dept of CSE Page 12


Automata Theory and Computability Languages and strings

Dept of CSE Page 13


Automata Theory and Computability Language Hierarchy

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.

Dept of CSE Page 14


Automata Theory and Computability Language Hierarchy

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! }

Athmaranjan K Dept of ISE Page 15


Automata Theory and Computability Computation

Computation: is any type of calculation or use of computer technology in information processing.


Computational model acts on its inputs under the control of an algorithm to produce its results. The
three key ideas of computation are:
 Decision Problem
 Non-determinism
 Functions on Languages.
Decision Procedure: Decision problem is a kind of problem that could make the decision about Yes
or No. An algorithm is a detailed procedure that illustrates how to accomplish certain task. The
decision procedure is an algorithm used to solve decision problem. The decision procedures either
produce the result Yes or No for acceptance or rejection of the input.
Non-determinism: Non-determinism is a property that leads two different paths or solutions for the
same input. During the computations, this non-determinism is converted to determinism to obtain the
exact solutions.
Functions on languages: There are some useful functions that can be performed on languages. For
example-simple functions such as complement, concatenation, union, intersection and kleen star. All
these functions are defined by straight forward extension of standard operations on strings and
alphabets.

Dept of CSE Page 16


Automata Theory and Computability Finite State Machine

FINITE STATE MACHINE (FSM or FA)


Briefly explain Finite State Machine.
Finite state machine is a mathematical model of a computational device whose input is a string and
whose output is one of two values we can call Accept or Reject. The input when given to the
machine is processed by various states, these states are called as intermediate states.
The input string fed to a FSM one character at a time, from left to right. The FSM has a start state
with an unlabelled arrow leading to it and some number (zero or more) of accepting states which is
represented with double circles. The FSM starts in its start sate. As each character is read, the FSM
changes state based on the transitions. If a FSM ‘M’ is in accepting state after reading the last
character of some input string ‘s’ then we say that ‘M’ accepts ‘s’ otherwise rejects it.
Block diagram of FSM:

Types of Finite State Machine:


There are two types of FSM’s:
1. Deterministic Finite State Machine ( DFSM or DFA)
2. Non Deterministic Finite State Machine ( NDFSM or NFA)
FSM Example: The control mechanism of elevator. This mechanism only remembers the current
floor number pressed, it does not remember all the previously pressed numbers

Deterministic Finite State Machine ( DFSM or DFA)

Dept of CSE Page 17


Automata Theory and Computability Finite State Machine- DFSM

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

Language Accepted by a DFSM (DFA): A DFSM M accepts the string w if (S, w) *


(q, ) for
some q € AM. Any configuration of (q, ) for some q € AM is called an accepting configuration of M.

Pattern Recognition type DFSM (DFA) Design Problems:


Draw a DFSM (DFA) to accept the language contains strings of a’s and b’s having at least one a.

Dept of CSE Page 18


Automata Theory and Computability Finite State Machine- DFSM

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} )

Where δ is given by the transition function:


δ = {((q0, a), q1),
((q0, b), q0),
((q1, a), q1),
((q1, b), q1)}

OR
δ is given by the transition table: ∑

state a b
q0 q1 q0

q1 q1 q1

Dept of CSE Page 19


Automata Theory and Computability Finite State Machine- DFSM

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} )

Where δ is given by:


δ = {((q0, a), q1), ((q0, b), q0), ((q1, a), d), ((q1, b), q1), ((d, a), d), ((d, b), d)}
state d is considered as dead state

All Strings of a’s and b’s ending with abb. OR


Obtain a DFSM (DFA) to accept the language L = { wabb | w € (a,b)* }
Minimum string in L is abb, so the DFA for minimum string is given by:

Therefore the DFA for the given problem is M = ({ q0, q1,q2,q3}, { a, b}, δ, q0, {q3} )
Where δ is as shown in transition diagram.

Dept of CSE Page 20


Automata Theory and Computability Finite State Machine- DFSM

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:

Obtain a DFA to accept the language L = { waabw | w € ( a, b)* }


OR
Obtain a DFA to accept the language L contains strings of a’s and b’s with substring aab

Minimum string in L is aab, so the DFSM (DFA) for the minimum string is:

DFSM (DFA) M = ( { q0, q1,q2,q3 }, { a, b}, δ, q0, {q3} )

Dept of CSE Page 21


Automata Theory and Computability Finite State Machine- DFSM

Where δ is given in TD.

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.

Obtain a DFSM (DFA) to accept the language L = { abw | w € ( a, b)* }

Dept of CSE Page 22


Automata Theory and Computability Finite State Machine- DFSM

OR
Obtain a DFSM (DFA) to accept the language L contains strings of a’s and b’s starting with ab.

Minimum string is ab, DFA corresponding to this is given by:

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 :

DFSM (DFA) M = ( { q0, q1, q2, q3 }, { 0, 1}, δ, q0, {q3} )


Where δ is as shown in transition diagram.

Dept of CSE Page 23


Automata Theory and Computability Finite State Machine- DFSM

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

DFA or DFSM M = ( { q0, q1, q2, d }, { a, b}, δ, q0, {q2} )


Where δ is as shown in transition diagram.

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

DFA M = ( { q0, q1, q2, q3, q4 }, { a, b}, δ, q0, {q3, q4} )


Where δ is as shown in transition diagram

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.

Dept of CSE Page 25


Automata Theory and Computability Finite State Machine- DFSM

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:

Dept of CSE Page 26


Automata Theory and Computability Finite State Machine- DFSM

Minimum string is 0011 and its DFA

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:

Dept of CSE Page 27


Automata Theory and Computability Finite State Machine- DFSM

Obtain DFSM (DFA) to accept the following languages on Σ = { a, b}


i. The set of all strings that either begins or ends or both with substring ab.
ii. The set of strings with at least one “a” and exactly two ‘b’s. OR
L = { w | Na(w)  1 and Nb(w) = 2 }. Or L ={ w | #a(w)  1 and #b(w) = 2 }.
iii. Set of all strings of even length. OR L = { w | w is even length and w €{ a,b)*}

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:

Dept of CSE Page 28


Automata Theory and Computability Finite State Machine- DFSM

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

Dept of CSE Page 29


Automata Theory and Computability Finite State Machine- DFSM

i. Set of all strings of a’s and b’s of even length.


DFA M = ({ q0, q1 }, { a, b}, δ, q0, {q0,}) where δ is as shown in transition diagram:

Obtain a DFA to accept the language L = { (01)i 12j | i  1, j  1 }


The possible strings in L = {0111, 01010101…11, ……..}
ie: L = { strings of all 0’s and 1’s with at least one 01 and followed by an even number of 1’s with
minimum two 1’s (no zero 1’s) }
The DFA M = ({ q0, q1, q2, q3, q4, d}, { 0, 1}, δ, q0, {q4 }) where δ is as shown in transition
diagram:

Dept of CSE Page 30


Automata Theory and Computability Finite State Machine- DFSM

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

Dept of CSE Page 31


Automata Theory and Computability Finite State Machine- DFSM

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

Other DFSM problems


****
Design a DFSM for L = {w € {a, b}*: every a is immediately followed by a b}. Also explain how
DFSM will process the input string: abbabab
Language contains strings of a’s and b’s such that whenever a appears in a string, it must be
followed by a b and b can be followed anything.( no restriction)
L= {ϵ, b, bb, ab, abb, abab, ababbbbbb……………………………..}
The DFSM M = ({ q0, q1, d}, { a, b}, δ, q0, {q0}) where δ is as shown in transition diagram

Dept of CSE Page 32


Automata Theory and Computability Finite State Machine- DFSM

DFSM operation in processing the string: abbabab


(q0 abbabab) (q1 bbabab) (q0 babab) (q0 abab) (q1, bab) (q0 ab) (q1 b) (q0 ϵ)
Since q0 is an accepting state, M accepts the given input string abbabab
( indicates one step move)

Design a DFSM for L = {w €{a, b}* : every a region in w is of even length}


Language L contains strings of a’s and b’s in which any number of b’s immediately preceded or
followed by even number of a’s .
L= {ϵ, b, bb, aab, aabb, baa, aabaab, aabaaaabbbbbb……………………………..}
The DFSM M = ({ q0, q1, d}, { a, b}, δ, q0, {q0}) where δ is as shown in transition diagram

Design a DFSM for L = {w € { 0, 1}* : w has odd parity}.


Language L contains strings of 0’s and 1’s in which number of 1’s must be odd and number 0’s can
be anything.
L = {1, 01, 001, 100,111,…………………………………..}
The DFSM M = ({ q0, q1}, { 0, 1}, δ, q0, {q1}) 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.

Dept of CSE Page 33


Automata Theory and Computability Finite State Machine- DFSM

NOTE: The language accepted by DFSM is called Regular language.

Floating Point Numbers:


 A floating point number is an optional sign, followed by a decimal number, followed by an
optional exponent.
 A decimal number may be of the form x or x.y, where x and y are nonempty strings of
decimal digits.
 An exponent begins with E and is followed by an optional sign and then an integer.
 An integer is a nonempty string of decimal digits.
So, for example, these strings represent floating point numbers:
+3.0, 3.0, 0.3El, 0.3E+l, -0.3E+l, -3E8

Design a DFSM for L= {w : w is the string representation of a floating point number}.


The DFSM M = ({ q0, q1,q2, q3, q4,q5, q6, q7 }, { +,-,d . E}, δ, q0, {q4, q7}) 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.

Dept of CSE Page 34


Automata Theory and Computability Finite State Machine- DFSM

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)* }.

Dept of CSE Page 35


Automata Theory and Computability Finite State Machine- DFSM

ie: (|w| mod 3 not equal to 0)


The DFA M = ({ q0, q1, q2}, { a, b}, δ, q0, {q1, q2}) 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 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

Dept of CSE Page 36


Automata Theory and Computability Finite State Machine- DFSM

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:

Dept of CSE Page 37


Automata Theory and Computability Finite State Machine- DFSM

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 }

Dept of CSE Page 38


Automata Theory and Computability Finite State Machine- DFSM

The possible states for the given DFA is K = K1 X K2


K = { (A0,B0 ), ( A0,B1), (A1,B0), ( A1,B1), (A2,B0), (A2,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:

Dept of CSE Page 39


Automata Theory and Computability Finite State Machine- DFSM

****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)

Dept of CSE Page 40


Automata Theory and Computability Finite State Machine- DFSM

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:

Divisible by “n” problems for strings represented as binary or decimal numbers:


Procedure:
Construction of DFSM (DFA) which accepts the strings over Σ, represented as binary or decimal
number can be obtained using the following method
For any given problem if the number is divisible by ‘n’, then we may have ‘n’ number of DFA
states. These states are nothing but the remainders of divisible by ‘n’ problem.
For example if the numbers are interpreted as binary numbers and divisible by 5 then we have total
five states DFA, where state q0 represents remainder 0, q1 represents remainder 1, q2 remainder 2, q3
remainder 3 and q4 remainder 4 respectively.
The transition function for the above example is defined as follows:
Dept of CSE Page 42
Automata Theory and Computability Finite State Machine- DFSM

δ (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.

Dept of CSE Page 43


Automata Theory and Computability Finite State Machine- DFSM

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:

Dept of CSE Page 44


Automata Theory and Computability Finite State Machine- DFSM

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}.

Dept of CSE Page 45


Automata Theory and Computability Finite State Machine- DFSM

2. {w € {a, b}*: w does not end in ba }.

3. {w € {0 - 9}*: w corresponds to the decimal encoding, without leading 0’s, of an odd natural
number }

4. w € {a, b}*: w has neither ab nor bb as a substring }.

Dept of CSE Page 46


Automata Theory and Computability Finite State Machine- DFSM

5. {w € {a, b}*: w has both aa and bb as a substring }.

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.

7. {w € {0, 1}*: none of the prefixes of w ends in 0}

Disadvantages of DFSM (DFA):


 Construction of DFA is difficult for the complex languages.
 DFA cannot guess about its input.
 DFA is not very powerful, at any given time DFA is in only one state.

Dept of CSE Page 47


Automata Theory and Computability Non-Deterministic Finite State Machine

Non-Deterministic Finite State Machine (NDFSM or NFA)


Define NDFSM or NFA.

A nondeterministic FSM (or NDFSM) M is a 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 ∑ U {ϵ} to 2K (finite set of subset of K)
Let w be an element of ∑*. Then we will say that:
 M accepts 'w if at least one of its computations accepts.
 M rejects ·w if none of its computations accepts.
'The language accepted by M, denoted L(M), is the set of all strings accepted by M.

What is the difference between DFSM (DFA) and NDFSM (NFA)

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

Dept of CSE Page 49


Automata Theory and Computability Non-Deterministic Finite State Machine

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

The operation of NDFSM M is as a tree and it is shown below:

NDFSM Design problems

Design a NDFSM (NFA) for L = {w € {a, b}*: w is made up of an optional a followed by aa


followed by zero or more b's }
NDFSM (NFA) M =({ q0, q1, q2, q3}, { a, b}, δ, q0, { q3}) where δ is as shown in transition diagram:

Design a NDFSM (NFA) for L = {w € {a, b}*: w = aba or |w| is even }

Dept of CSE Page 50


Automata Theory and Computability Non-Deterministic Finite State Machine

NDFSM (NFA) M =({ q0, q1, q2, q3, q4, q5, q6}, { a, b}, δ, q0, { q4, q5}) where δ is as shown in
transition diagram:

Obtain an NDFSM (NFA) for the following languages:


i. L = { ababn or aban | n  0 }
ii. L = { w (ab + ba) | w € ( a,b)* } ie: ending with ab or ba
iii. L = { abw | w € ( a,b)* } ie: starting with ab
iv. L = { wab | w € ( a,b)* } ie: ending with ab
v. L = { awa | w € ( a,b)* } ie: starting with “a” and ending with “a”.

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:

Dept of CSE Page 51


Automata Theory and Computability Non-Deterministic Finite State Machine

ii. L = { w (ab + ba) | w € ( a,b)* }

iii. L = { abw | w € ( a,b)* } .


NFA for the above problem is M =({ q0, q1, q2}, { a, b}, δ, q0, { q2) where δ is as shown in
transition diagram:

iv. L = { wab | w € ( a,b)* } .


NFA for the above problem is M =({ q0, q1, q2}, { a, b}, δ, q0, { q2) where δ is as shown in
transition diagram:

v. L = { awa | w € ( a,b)* }.

Dept of CSE Page 52


Automata Theory and Computability Non-Deterministic Finite State Machine

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}.

Dept of CSE Page 53


Automata Theory and Computability Non-Deterministic Finite State Machine

NDFSM (NFA) M = ({ q0, q1, q2, q3, q4 }, { a, b}, δ, q0, { q4}) where δ is as shown in transition
diagram:

Analyzing Nondeterministic FSMs


Given an NDFSM M, we will see how can we analyze it to determine what strings it accepts? One
way is to do a depth-first search or the paths through the machine. Another is to imagine tracing the
execution of the original NDFSM M by following all paths in parallel.
Example:

Take input string w = abb


Initially, M is in q0. If it sees an input symbol a, it can loop to state q0 or go to q1• So we will think
of it as being in the set of slates (q0, q1}. Suppose it sees a b next. From q0 it can go to q0 or q6. From
q1, it can go to q2 So after seeing the string ab, M is in {qo, q2, q6}. Suppose it sees a b next. From q0
it can go to q0 or q6. From q2 it can go to q3. From q6 it can go nowhere. So, after seeing abb, M is in
{q0, q3, q6} and so forth. If when all the input has been read, M is in at least one accepting state (in
this case, q5 or q9) then it accepts otherwise it rejects (string abb is rejected).

Consider the following NDFSM M:

Dept of CSE Page 54


Automata Theory and Computability Non-Deterministic Finite State Machine

For each of the following strings w, determine whether w € L( M):


a. aabbba.
b. bab.
c. baba.
Ans:
a) aabbba. Yes.
b) bab. No.
c) baba. Yes

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.

Dept of CSE Page 55


Automata Theory and Computability Non-Deterministic Finite State Machine

eps (q0) = {q0, q1, q2 }


eps (q1) = {q0, q1, q2 }
eps (q2) = { q0, q1, q2}
eps (q0) = { q3}
The Equivalence of Nondeterministic and Deterministic FSMs
1. If There is a DFSM for L, There is an NDFSM for L
2. If There is an NDFSM for L, There is a DFSM for L

Conversion of NDFSM to DFSM:


Given an NDFSM M = ( K, ∑, δ, S, A ) that accepts some language L, then there exists an
equivalent DFSM M` that accepts L. The states of M' will correspond to sets of states in M.
So M’ = ( K’, ∑, δ’, S’, A’). where:
K' contains one state for each element of p(K).
s' = eps (s).
A' = { Q subset of K: Q ∩A≠Ø}.
δ’(Q, c)= U {eps (p) : q € Q ((q, c, p) € ∂)}.
Algorithm (Procedure) to convert NDFSM to DFSM:
Explain the algorithm used to convert NDFSM to DFSM
1.For each state q in K do:
Compute eps(q).

Dept of CSE Page 56


Automata Theory and Computability Non-Deterministic Finite State Machine

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:

Add the transition (Q, a, new-state) to ∂’


If new-state does not belongs to active-state, then insert it into active-states.
4. K' = active-states.
5. A' = {Q € K': Q∩A # Ø }.

1. Convert the following ε-NFA to DFA


OR
Convert the following NDFSM to DFSM

ε 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:

Dept of CSE Page 57


Automata Theory and Computability Non-Deterministic Finite State Machine

1. Compute epsilon closure of each state:


eps (p) = { p, q, r }
eps (q) = { q }
eps (r) = { r }
2. Start state of DFSM (DFA) s’ = eps (start state of NDFSM) = eps (p) = {p, q, r}
3. Compute ∂’ for DFSM:
Initially Active states = { p, q, r } (ie: start state of DFSM)
Define the transitions in state {p, q, r} on input ∑ = {a, b, c}
∂’({p, q, r}, a) = eps{∂(p, a) U ∂(q, a) U ∂( r, a) }

= 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.)

∂’({p, q, r}, c) = eps{∂(p, c) U ∂(q, c) U ∂( r, c) }

= eps{ r U {p, q}U Ø } = eps({ p, q, r})


= eps{ p} U eps(q) U eps(r) = {p, q, r} U {q } U {r} = { p, q, r }
∂’(({p, q, r}, b), { p, q, r})

Dept of CSE Page 58


Automata Theory and Computability Non-Deterministic Finite State Machine

Active states = {{ p, q, r }, {q, r }}


Now define the transitions in state {q, r} on input ∑ = {a, b, c}
∂’({q, r}, a)) = eps{∂(q, a) U ∂(r, a) }

= 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 (Ø) = Ø

∂’(r, c) = eps(∂(r, c)) = eps (Ø) = Ø


Active states = {{ p, q, r }, {q, r }, {r}, Ø }
Now define the transitions in state { Ø } on input ∑ = {a, b, c}
∂’(Ø, a) = eps(∂(Ø, a)) = eps (Ø) = Ø

∂’(Ø, b) = eps (Ø, b)) = eps (Ø) = Ø

∂’(Ø, c) = eps(∂(Ø, c)) = eps (Ø) = Ø


Since there is no more new states and active-states did not change; so we will stop the process.
4. Finally the number of states in DFSM (DFA) is K’ = {{p, q, r}, { q, r}, {r}, Ø }
5. The final states of DFSM (DFA) is A’ = {{ p, q, r}, {q, r}, {r}}

Dept of CSE Page 59


Automata Theory and Computability Non-Deterministic Finite State Machine

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 :

2. Convert the following ε- NFA to DFA, by computing ε-closure of each state.


OR
Convert the following NDFSM to DFSM, by computing ε-closure of each state

δ ε 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:

1 Compute epsilon closure of each state:


eps (p) = { p, q, r }

Dept of CSE Page 60


Automata Theory and Computability Non-Deterministic Finite State Machine

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}

3 Compute ∂’ for DFSM:


Initially Active states = { p, q, r } (ie: start state of DFSM)
Define the transitions in state {p, q, r} on input ∑ = {a, b}
∂’({p, q, r}, a) = eps{∂(p, a) U ∂(q, a) U ∂( r, a) } = eps({p, q, r}) = eps(p) U eps(q) U eps(r)
= {p, q, r} existing state
∂’(({p, q, r}, a), {p, q, r})
∂’({p, q, r}, b) = eps{∂(p, b) U ∂(q, b) U ∂( r, b) } = eps({p, r})
= {p, q, r} existing state
∂’(({p, q, r}, b), {p, q, r})
4 Finally the number of states in DFSM (DFA) is K’ = {p, q, r}
5 The final states of DFSM (DFA) is A’ = { p, q, r}
The resultant DFSM or DFA is given by
M = ({p, q, r}, {a, b} , δ, {p, q, r }, {p, q, r}}) and δ is as shown in transition diagram:

The set of all strings of length 3 or less accepted by this automaton:


L = { ε, a, b, aa, ab, ba, bb, aaa, aab, aba, baa, bab, bba, bbb}
Exercises
By computing eps closure of each state, convert the following NFA to DFA

Dept of CSE Page 61


Automata Theory and Computability Non-Deterministic Finite State Machine

Eps closure:

Dept of CSE Page 62


Automata Theory and Computability From FSMs to Operational System

From FSMs to Operational Systems


An FSM is an abstraction. We can describe an FSM that solves a problem without worrying about
many kinds of implementation details. In fact, we don't even need to know whether it will be etched
into silicon or implemented in software.
FSMs for real problems can be turned into operational systems in many number of ways
 An FSM can be translated into a circuit design and implemented directly in hardware. For
example. it makes sense to implement the parity checking FSM.
 An FSM can be simulated by a general purpose interpreter. In other cases, a simulation can
he used to check a design before it is translated into hardware.
 An FSM can be used as a specification for some critical aspect of the behavior of a complex
system. The specification can then be implemented in software just as any specification
might be. And the correctness of the implementation can be shown by verifying that the
implementation satisfies the specification

Dept of CSE Page 63


Automata Theory and Computability Simulators for FSMs

Simulators for FSMs


Once we have created an FSM to solve a problem, we may want to simulate its execution.
Consider the following deterministic FSM M that accepts the language L = { w € {a, b}*: w contains
no more than one b}.

We could view M as a specification for the following program:


Until accept or reject do:
S: s =get-next-symbol.
If s =end-of-file then accept.
Else if s = a then go to S.
Else if s = b then go to T.
T: s =get-next-symbol.
If s = end-of-ftle then accept.
Else if s = a then go to T.
Else if s = b then reject
End

A simple interpreter for a deterministic FSM M = ( K, ∑, δ, S, A )


dfsmsimulate(M: DFSM, w: string) =
1. st = s.
2. Repeat:
2.1. c = get-next-symbol(w).
2.2. If c ≠ end-of-file then:
2.2.1. st = δ(st, c).
until c = end-of-file.
3. If st € A then accept else reject

Dept of CSE Page 64


Automata Theory and Computability Minimizing FSMs

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:

NOTE: No equivalence class of is empty, and


Every string in ∑* is in exactly one equivalence class of

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

prior a that is not followed by a b]


[3] [aa, abaa…………………...] [ all strings that contains at least one
instance of aa
*
Explanation: ∑ = { ɛ, a, b, aa, ab, ba, bb,………………..}
L = { ɛ, b, ab, bb, abb, bab, ……………….}
Take the first equivalence class [1] and arbitrarily assigning ɛ to it. Now consider one string from ∑*.
Let it be a, and see a and ɛ are equivalent (indistinguishable) strings.
Take one string z which is defined in L; ie: z = ab
ɛ ab = ab € L and aab does not belongs to L, so both the strings ɛ and a are not equivalent. So we
create a new equivalence class [2] and put a in it.
Let us consider one more string from ∑* ie: b and see ɛ and b are equivalent.
z = ab; ɛ ab = ab € L and bab € L. So b goes into [1 ).
Let us consider one string = aa
ɛ ab = ab € L and aaab does not belongs to L, so both the strings ɛ and aa are not equivalent
Take z = b; a b = ab € L and aab does not belongs to L, so both the strings a and aa are not
equivalent. So we create a new equivalence class [3] and put a in it.
NOTE: No equivalence class can contain both strings that are in L and strings that are not. This is
clear if we consider the continuation string ɛ. If x €L then xɛ € L. If y does not belongs to L then yɛ
does not belongs to L. So x and y are distinguishable by ɛ.

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

Dept of CSE Page 66


Automata Theory and Computability Minimizing FSMs

L = an bn. then has an infinite number of equivalence classes.


M has n states and there are n equivalence classes of

Minimizing an Existing DFSM:


What are indistinguishable (equivalent) and distinguishable (not-equivalent) states?
Indistinguishable states (Equivalent): Two states p and q in Finite state machine M are
equivalent, which we will write if for all strings w € ∑* either w drives M to an accepting
state from both p and q or it drives M to a rejecting state from both p and q.
Distinguishable states (Not-Equivalent): Two states p and q in Finite state machine M are
distinguishable(not-equivalent), if for all strings w € ∑*, w drives M to an accepting state from state
p and w drives M to a rejecting state from state q or vice versa.

Consider the following FSM that accepts L: determine the equivalent states.

Dept of CSE Page 67


Automata Theory and Computability Minimizing FSMs

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

Dept of CSE Page 68


Automata Theory and Computability Minimizing FSMs

*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.

Dept of CSE Page 69


Automata Theory and Computability Minimizing FSMs

Finally 1 equivalent classes of states are:


1 equivalent classes of states: [A, C, E] [F] [B, D]
Step 4: 2 equivalent states: In order to construct 2 equivalent state, we have to refer 1 equivalent
states.
To check whether A and C are 2 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 are 2 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 2 equivalent.
B and D
δ(B, a) = C and δ(D, a) = F ----------belongs to different class
Therefore B and D are not 2 equivalent, so we have to split the class [B, D] of 1 equivalent state into
two classes [B] and [D] in 2 equivalent states.
2 equivalent classes of states: [A, C, E] [F] [B] [D]
Step 5: 3 equivalent states: In order to construct 3 equivalent states, we have to refer 2 equivalent
states.
δ(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 are 3 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 3 equivalent.
3 equivalent classes of states: [A, C, E] [F] [B] [D]
Since there is no change in 2 and 3 equivalent classes of states, so we stop the process.
The minimized DFSM contains 4 states: {[A, C, E], [B], [D], [F] }
Where states A, C and E are equivalent (Indistinguishable states), so that we can merge these states
into a single state.

Dept of CSE Page 70


Automata Theory and Computability Minimizing FSMs

Minimized DFSM:

Minimize the following DFA using partioning of equivalence class method.

Step 1: Since state D is not reachable from start state, we can eliminate that state.
So the resultant transition table:

Step 2: Initially 0 equivalent classes: [A, B, E, F, G, H] [C]


Step 3: 1 equivalent state classes: [A, E, F, G] [B, H] [C]
Step 4: 2 equivalent state classes: [A, E] [F] [G] [B, H] [C]

Dept of CSE Page 71


Automata Theory and Computability Minimizing FSMs

Step 5: 3 equivalent state classes: [A, E] [F] [G] [B, H] [C]

[A, E] and [B, H] are indistinguishable or equivalent states.


[C], [F] and [G] are distinguishable states.
Minimized DFSM:

By computing Distinguishable and Indistinguishable states, construct minimum state equivalent


automata for the following DFSM:
δ 0 1
→A B E
B C F
*C D H
D E H
E F I
*F G B
G H B
H I C
*I A E

Step 1: Initially 0 equivalent class of states : [ A, B, D, E, G, H] [ C, F, I]


Step 2: 1 equivalent class of states: [A, D, G] [B, E, H] [C, F, I]
Step 3: 2 equivalent class of states: [A, D, G] [B, E, H] [C, F, I]
Indistinguishable or equivalent states are: [A, D, G], [B, E, H] and [C, F, I]
Minimized DFSM:

Dept of CSE Page 72


Automata Theory and Computability Minimizing FSMs

Minimize the following DFSM using partioning of equivalence class method

Transition Table:
a b
→*q1 q2 q4
q2 q3 q5
*q3 q2 q6
q4 q5 q1
q5 q6 q2
q6 q5 q3

Step 1: Initially 0 equivalent class of states : [q2, q4, q5, q6 ] [q1, q3 ]


Step 2: 1 equivalent class of states : [q2] [q4, q6] [q5] [q1, q3 ]
Step 3: 2 equivalent class of states : [q2] [q4, q6] [q5] [q1, q3 ]
No further splitting is required. The minimized DFSM has the states: [q1, q3], [q2], [q4, q6], [q5]
With transition as shown below:

Dept of CSE Page 73


Automata Theory and Computability Minimizing FSMs

Dept of CSE Page 74


Automata Theory and Computability Canonical Form for Regular Languages

A Canonical Form for Regular Languages


A canonical form for FSMs deals with the property that two FSMs share a canonical form if they
accept the same language. For any machine M, once its canonical form is constructed by applying
some algorithm, then it can be very easy to answer some questions about FSM.
Example: To test whether two FSM’s are equivalent, it would be sufficient to construct the
canonical form for each of them and test whether the two forms are identical.
Minimization of DFSM algorithm constructs minimal DFSM machine for any machine M that
accepts L(M). All minimal machines for L(M) are identical except possibly for state names. So, if
we could define a standard way to name states, we could define a canonical machine to accept L(M)
Algorithm to build a canonical form for a FSM M
1. Let M’ is the FSM constructed by converting NDFSM to DFSM M
2. M# = minimized FSM of M’
3. Create a unique assignment of names to the states of M# as follows:

3.1 Call the start -state q0


3.2 Define an order on the elements of ∑
3.3 Until all states have been named do:
Select the lowest numbered named state that has not yet been selected. Call it q.
Create an ordered list of the transitions out of q by the order imposed on their labels.
Create an ordered list of the as yet unnamed states that those transitions enter by
doing the following: If the first transition is (q. c1, p1 ), then put p1 first. If the second
transition is (q. c2, p2) and p2 is not already on the list, put it next. If it is already on
the list, skip it. Continue until all transitions have been considered. Remove from the
list any states that have already been named.
Name the states on the list that was just created: Assign to the first one the name qk
where k is the smallest index that hasn't yet been used. Assign the next name to the
next state and so forth until all have been named.
4. Return M#

****Methods for comparing two FSM’s:

Dept CSE Page 75


Automata Theory and Computability

Let M and M’ be two FSM’s and ∑ is a set of input strings:


 We will construct a transition table have state pair wise entries (p, q) where p € M and q € M’
for each input symbol.
 If we get a pair as one final state and other non-final state then we terminate construction of
transition table declaring that two FSMs are not equivalent.
 The construction of transition table gets terminated when there is no new pair appearing in
the transition table.
Check whether the following two DFSM’s are equivalent.

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.

Check whether the following two DFSM’s are equivalent

Dept CSE Page 76


Automata Theory and Computability

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.

FINITE STATE TRANSDUCER

Dept CSE Page 77


Automata Theory and Computability

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:

Moore machine for simple traffic light is as shown in figure.

Construct a Moore machine to generate 1’s complement of a given binary number.


If we apply input 1, then its output will be 0 and if input is 0 then output will be 1.

Dept CSE Page 78


Automata Theory and Computability

Construct a Moore machine to determine residue mod 3 for binary number.

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:

Dept CSE Page 79


Automata Theory and Computability

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)

Dept CSE Page 80


Automata Theory and Computability

For input string = abbabb machine has to print two ‘1’s.


a b b a b b
A → B → C → D → B → C → D
↓ ↓ ↓ ↓ ↓ ↓ ↓
0 0 0 1 0 0 1

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:

Construct a Mealy machine to generate 1’s complement of a given binary number

Design a Mealy machine for computing the 2’s complement of binary number

Dept CSE Page 81


Automata Theory and Computability

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.

Dept CSE Page 83

Vous aimerez peut-être aussi