You are on page 1of 151

UNIT I

INTRODUCTION

1.1 INTRODUCTION

 The study of abstract devicea is the called automata theory.


 Finite Automata is a mathematical model that accepts a set of inputs, process
through a set of states, generates an output.
 Automation helps in
o Designin and checking the behavior of digital circuits
o Pattern searching in websites
o Verifying systems like communication protocols for secure data transfers
o Designing lexical analyzers in compliers
 Finite automation model is a study of machines.
History
Alan Turing introduced an abstract machine in 1930’s. This machine had all the capabilities of
today’s computer.
In 1940’s and 1950’s, the machines were simplified to finite automation machines.
Researchers proposed the automation model in order to model the functions of human brain.
The linguist Noam Chomsky made a study on formal grammars in late 1950’s .These
grammars provided the basis of compliers.
S.Cook extended Turing’s study in 1969, which separated the problems as solvable and
unsolvable. He classified problems as NP-Hard and as NP-Complete.
Example of a Finite state system: Switch operation

PUSH

Start
OF ON
F

PUSH
Introduction 1.2

Here,

 When the electric switch = “ON” indicates logic ‘1’ when pushed from start state.

 Goes to ‘OFF’ state when pushed from ‘ON’ state.


Example: Pattern searching of sting = “then”

t h e n
t t the the
h n

Example: Pattern searching of sting = “automata

a u t o m a t
a a au auto auto autom automa
u t m a t

a
automat
a

1.2 BASIC MATHEMATICAL NOTATION AND TECHNIQUES


1.2.1 Basic Mathematical Objects
SETS [A]
A set is collection of elements of finite number.
Example:
A = {10, 01, 00, 11}
B = {w | w is a set of prime numbers less than 100}
w B
C = {r | r is a set of strings generated from vowels}
r C
SUBSET [  ]
Let A1and A2 are two sets, then A1 is a subset of A2 [indicated as A1  A2 ], if every element of
A1 is in A2.
Example:
A1 = {1, 2, 3, 4}
A2 = {1, 2, 3, 4, 5}
1.3 Theory of Computation

A1  A2
COMPLEMENT OF A SET [A']

Let A be a set of finite number of elements. Then A' is a set of elements that are not the
elements of set A. [A' A]

Example:

A1 = {a, e, i, o, u}

A' = { all alphabets except vowels}

OPERATIONS ON SETS

Union [ ]

The union of two sets results in a set containing the elements of both the sets (without
repeatition of elements).

Example:

A1 = {1, 3, 5, 7}

A2 = {1, 2, 3, 4,}

A1 A2 = {1, 2, 3, 4, 5, 7}

Intersection [ ]

The intersection of two sets contains a set of elements that are available in both the sets.

Example:

A1 = {1, 3, 5, 7}

A2 = {1, 2, 3, 4}

A1 A2 = {1, 3}

Difference [ - ]

The difference of two sets A and B results in the set of elements that are in A and not in B.

Example:

A1 = {1, 3, 5, 7}

A2 = {1, 2, 3, 4}
Introduction 1.4

A1 – A2 = {5, 7}  [A1 – A2 = A1 A2']

LAWS ON SETS
Commutative Laws
A B =B A

A B=B A

Associative Laws
A (B C) = (A B) C

A (B C) = (A B) C

Distributive Laws
A (B C) = (A B) (A C)

A (B C) = (A B) (A C)

Idempotent Laws
A A= A

A B=A

Absorptive Laws
A (A B) = A

A (A B) = A

De Morgan’s Laws
(A B) ' = A' B'

(A B) ' = A' B'

Other Laws
(A') ' = A
A A' =
A A' = Universal set, ’U’
A =A
1.5 Theory of Computation

A =
A U=U

A U=A

Equality of sets [ = ]

Two sets are set to be equal if both the sets contain the same elements.

Example:

A = {1, 3, 5, 7}

B = {set of odd numbers less than 8}

Then, A = B

Empty set [ ]

A set containing no elements is said to be an empty set.

Example:

A = { set of natural numbers between 1 and 2}

A= or { }

Power of a set [ Ak ]

The power of a set A, denoted by A k is the set containing all elements of A, whose length is
less than or equal to k.

Example:

A = {1, 2}

A2 = { , 1, 2, 12}

RELATIONSHIP OF SETS

Relation of two sets is the association of one set with other.

Types based on the properties of sets

1) Reflexive: Every element of the set is associated with itself.

2) Symmetric: Let a, b ϵ A, then a is related to b, and b is related to a [aRb = bRa]


Introduction 1.6

3) Transitive: If a b and b c, then a c. It is denoted as: aRb, bRc then aRc.

LOGIC

Logic deals with the logical proportions and connectives.

PROPOSITION
Proposition is a meaningful, objective, declarative statement that has a truth value as true /
false.
Example:
0 1, New Delhi is the capital of India, 5 is an even number, Chennai is in AP.
CONNECTIVE
Logical connective is a compound statement formed from simple proportions using a
connective such as

 and connective /conjunction

 or connective /disjunction

 Not / Negative connective


Example

p Q p^q p q p q

T T T T F F

T F F T F T

F T F T T F

F F F F T T

IMPLICATION
It is a conditional statement of the form, “if p then q” (p implies q), where p and q are simple
proportions.
It is denoted as p  q = p q

p q p q

T T T
1.7 Theory of Computation

T F F

F T T

F F T
1.2.2 Proofs
A proof is single line / multiline derivation that provide a convincing argument to make a
statement true.
Proofs can be derived from assumptions or facts or existing derivations.
Forms of Proofs
There are basically two forms of proofs. Thery are,
1) Deductive Proofs
2) Inductive Proofs
1.2.2.1 Deductive Proofs
These are sequence of statements which are derived from any assumption (hypothesis) or a
given initial statement to a conclusion statement.
The proofs are generated using some facts / accepted logics.
Example: If x 4, 2x x2
The hypothesis statement x 4
Conclusion statement 2x x2
This can be provided as substitution statement as:
When x = 4:- 24 42 16 16 True
When x = 5:- 25 52 32 25 True
When x = 6:- 26 62 16 36 True
When x = 3:- 23 32 16 9 False

Hence proved.

Inductive Proof
Introduction 1.8

It has a sequence of recursive / parametrical statements that handle the statement with lower
values of its parameters.

There are two types of inductions, namely -

 Mathematical Induction

 Structural Induction

Mathematical Induction

This follows induction principle that follows two steps, namely-

 Basis of Induction: It considers ‘n’ of f(n) as the lowest possible integer (n = 0 or 1)


and prove the given statement using substitution.
th
 Inductive step: Assume that the given statement is true for n value and prove the
statement for n = n+1.

This applies for all integer related statement.

Structural Induction

Structural Induction follows the mathematical induction concept but applies for trees and
expressions.

Example: Every tree has one node than it has edges, balancing parenthesis etc.

Additional forms of proofs

 Proofs about sets

 Proof by contradiction

 Proof by counter example

 Direct Proofs

Proofs about set

Proof about the set includes the proofs on the properties of the sets.

Example: Commutative law, Distributive law etc


1.9 Theory of Computation

Consider, A = P  Q, B = Q  P

Since P  Q = Q  P ( by Commutative law), we prove that A = B.

This proof follows “if and only if” type. This is A= B is true if and only if P  Q = Q  P is
true.

Proof by contradiction

The proof p  q is true, then the method follows a contradictory assumption that p q and
from the result, it proves the assumption is false and thus proves, p  q.

Example:

To prove P  Q = Q  P, we first assume that P  Q ≠ Q  P.

Now consider an element, x from P that is also in Q.

xϵPQ

Thus all the element of P is taken and compared with that of Q.

Finally , P  Q = Q  P is proved [contradiction to our assumption]

Proof by Counter Example

Given a statement, that can be proved to be true for a domain of input instances, and false for
other inputs.

Example: a mod b ≠ b mod a

Let a = 5 and b = 10

a % b = 5 % 10 = 5

b % a = 10 % 5 = 0

Hence a % b b % a, the statement is true only if a = b.

Thus proved.

1.2.2.2 Inductive Proofs


Introduction 1.10

These are special type of proofs used to prove recursively defined objects.

It consists of sequence of parameterized statement that uses the statement itself with lower
values of its parameter.

Two steps

1. Basis of Induction  We start with the lowest possible value.

Example: To prove f(n) . We take n = 0 or 1 initially.

2. Inductive step Here we prove if f(n) is true, f(n+1) is also true.

SAMPLE PROBLEMS:
1. Prove that: 1+2 +3+ ………+n (n+1) / 2 using method of induction for (n>0).
Proof:
Basis of Induction
Let n = 1 [We cannot take n = 0 since U.H.S starts from 1]
L.H.S = 1

Since L.H.S = R.H.S Proved.


Inductive Step

We have

Sub n = n + 1

L.H.S 1 + 2 + 3 +…… + n =

When we substitute n = n+1,

L.H.S = Eg:
1.11 Theory of Computation

= ----- (1)

R.H.S =

When we substitute n=n+1,

R.H.S =

= ----- (2)

From (1) and (2), L.H.S = R.H.S


So the given hypothesis is proved.

2. For all

Basis of induction
Let n=1 (we can’t take n=0 since i=1 in L.H.S)

L.H.S = = 12 = 1
Introduction 1.12

R.H.S =

L.H.S = R.H.S.
Hence basis of induction is proved.
Inductive step

L.H.S: Sub n=n+1

= ----- (1)

R.H.S: Sub n=n+1

=
1.13 Theory of Computation

From (1) and (2) L.H.S = R.H.S


The hypothesis is proved.

3) P.T for every integer, the number is a multiple of 13.

Solution
Basis of induction
Let n = 0

L.H.S =

= 13 multiple of 13
Inductive proof
Let n=n+1

Multiple of 13

=
Introduction 1.14

= multiple of 13

The hypothesis is proved.


4) Show that is divisible by 3 for
Basis of induction
Consider n = 0
Divisible by 3

Hence proved.
Inductive step
Let us assume that is divisible by 3 for n, and try to prove the same for n=n+1

Using induction hypothesis,

((n+1) - nth term = a multiple of 3)

Multiple of 3 for all

Divisible by 3
1.3 FINITE AUTOMATA
1.3.1 Basic Definitions

Alphabet

An alphabet is a finite, non empty set of symbols.

Example: Binary alphabet


1.15 Theory of Computation

Lower - case letters set

Digits

String (w)
A string is a finite sequence of symbols chosen from some alphabet.
Example:

01101 is a string from

aa, bb, ab, ba are strings from

Empty string / Null string / /

An empty string is the string with zero occurrences of symbols.

Length of a string

Let be the string, then the length of the string, is the number of symbols
composing the string.
Example:

Concatenation of strings
The concatenation of two strings and is the string obtained by appending the symbols
of v to the right end of .
Example:

Power of an alphabet
Introduction 1.16

If is an alphabet, we can express the set of all string of a certain length from that alphabet
by using an exponential notation.

We define, to be the set of strings of length k, each of whose symbol is in

Example:

Let

Reversing a string

The reverse of the string is obtained by writing the string in reverse order.
Example:

Kleene closure

Let be an alphabet. Then the kleen closure, denotes the set of all strings over the
alphabet,

Example:

1) Let

2) Let
1.17 Theory of Computation

Kleene plus / Positive closure

Let be an alphabet. Then the positive closure, denotes the set of all strings over the
alphabet, except null string .

Example:

Let

Substring

The string, v if it appears within another string , then v is called as the substring of .

Example:

Let

v is a substring of

Let

Prefixes
Introduction 1.18

Suffixes

Palindrome

A palindrome is a string which is same when read in backward or forward direction.

is a palindrome

Example:

equal is a palindrome.

Language (L)

Alphabet finite set of symbols

String collection of alphabets

Language collection of appropriate strings

A set of strings taken from an alphabet is called a language.

Example:

= {ε, 11, 011, 0011, 1011, 0111, 101111, …}


Properties of String Operations
1. Concatenation of a string is always associative.

2. If u and v are two strings, then the length of this concatenation is the sum of the
langth of the individual lengths.

Example:
1.19 Theory of Computation

Operations of Languages
1. Product or concatenation

2. Reversal
The reversal of a language is a set of all string reverses.

3. Kleen Star/ Star Closure

4. Positive Closure

Other Operation on Set/Language


1. Union

L1  L2 = {x | x ϵ L1 or x ϵ L2}

2. Intersection

3. Difference:
Introduction 1.20

1.3.2 Definition Of Finite Automata [FA]


Finite Automata is a mathematical model of system with certain input and it is processed
through various intermediate states and finally gives certain output.
Model of FA

a1 a2 a3 a4 … Infinite tape

Read Head

Finite
CPU
control

Input Tape

 It is divided into number of cells.

 Each cell holds one symbol.


Read Head

 Reads one cell at a time and moves ahead.


Finite Control
 Acts like a CPU.
 Depending on current state and input symbol read from tape, it changes state.
Formal Definition of FA

FA consist of 5 Tuples,
Set of finite states.

Set of input alphabets

Transition function

Start state

Set of final states.

Representation of FA
1.21 Theory of Computation

1. Transition Diagram
2. Transition Table
Transition Diagram
It can be directed graph with vertices of a graph corresponding to states and edges indicates
transition from one state to another

0 1
q q q
0 1 2
Start
Final
state
state

 Start state indicated by circle.


 Start transition indicated by arrow.
 Final state indicated by double circle.
Transition Table
It is a tabular listing of the transition function which by implication tells us, set of states and
input alphabet.
b

a b
q q q
0 1 2

State a b

Input

*q2

Applications

1. Design of digital circuits.

2. String searching
Introduction 1.22

3. Communication protocols for information exchange.

4. Lexical analysis phase of a compiler.

Types

1. Deterministic Finite Automata [DFA]

2. Non-Deterministic Finite Automata [NFA]

1.4 DETERMINISTIC FINITE AUTOMATA [DFA] /FA

 The word deterministic refers to the fact the transition is deterministic.

 There is only one path for specific input from current state to next state.

DFA is defined by 5 tuples,

where,

Finite set of states.

Finite set of input symbols.

Initial state

Transition function

Final state / Accepting state

Properties of DFA

 There is only one path for an input from current state to next state.

 It contains only one final state.


PROBLEMS

1. Design a DFA for the language,

If
1.23 Theory of Computation

b
q q
0 1

Here,

Transition function,

2. Design a DFA that accept


a b a c
q q q q q Valid input: abac
0 1 2 3 4
Invalid inputs: aa, abc,
b, c a, b
a, c abaca, bbca, …
b, c a, b, c
q
Trap 2

3. Design a DFA that accept where every 0 in w has 1 immediately to its


right.
Introduction 1.24

0 1 Valid input
q q q 01
0 1 2

0 1
q q q 0101
0 1 0 2

1 1
101, 1101
0 1
q q q Invalid inputs:
0 1 0 2 00, 10, 1100, 1001, ….
0

Trap 
q
2 0, 1
4. Design a DFA that accept only ‘101’.

1 0 1
q q q q Valid input: 101
0 1 2 3
1 0 1
q q q q Invalid inputs:
0 1 2 3 00, 100, 010, 1010, …
1 0
0 0, 1

q
Trap 4
0, 1

5. Design a DFA that accepts string that starts with ‘ab’.

a b Valid inputs:
q q q 101
0 1 2

a, b
a b
q q q aba, abb, abaa, abbb,
0
abab, ….
1 2
1.25 Theory of Computation

a, b Invalid inputs:
a b
q q q ba, aa, aab, bab, aaaa,
0 1 2 baab, ….
b a
q
Trap 1

a, b

6. Design a DFA that accepts all strings of length atmost 5 over

Valid inputs:
0, 00, 000, 0000,
0, 1 0, 1 0, 1 0, 1 0, 1 00000, 1, 11, 111,
q q q q q q
1111, 1111, 10101,
0 1 2 3 4 5
010, 100, 0010, …

0, 1 0, 1 0, 1 0, 1 0, 1
q Invalid inputs:
q q q q q
101010, 0000000,
0 1 2 3 4 5
11110000,
0, 1 100011001,
q 1111111111, …
Trap 1

0, 1

7. Design a DFA that accepts even number of a’s over


Introduction 1.26

a a Valid inputs:
q q q
aa
0 1 2

a a
q q q
aaaa, aaaaaa, a8, a16, ...
0 1 a 2

a q a
3 Invalid input
q q a, aaa, aaaaa, a7, a17, ...
0 2
a a
q
1

8. Design a DFA that accepts a language, L having even number of 0s and 1s.

0
Valid inputs:
q q 00, 11, 0000, 1111, 08, 18, …
2 0 1

1 1

q
1

0
q q 0110, 0101, 1010, 1100, 110011,
2
0 1
10101010, 00001111, ...

1 1 1 1 Invalid inputs
0 0, 1, 000, 111, 101010, 110, 1101,
q 0100, …
q 0
1
1

9. Design a DFA that accepts all strings containing atleast two zeroes.
1.27 Theory of Computation

0 Valid inputs:
0
q q q 00
0 1 2

0, 1
0 0 00, 000, 0000, 00000, 0001,
q q q
000111, …
0 1 2
1
0, 1
0 0 100, 1100, 11100000, 110011,
q q q 1001, 11000010, …
0 1 2
1 1 1010, 10110, 11011011, 0101,
0, 1 1101101101, …
0 0
q q q
0 1 2 Invalid inputs:
1, 10, 111, 0111, 101, 11011,
01, …
10. Design a DFA that accepts strings ending with ‘00’ over

0 Valid inputs:
0
q q q 00
0 1 2

0
0 0 000, 0000, 00000, …
q q q
0 1 2
1
0
0 0 100, 1000, 1100 110000, …
q q q
0 1 2
1
0 0100, 101000, 110100, …
0 0
q q q
0
1 1 2

1
0 00100, 1000, 1010100, 001000
0 0
q q q
0
1 1 2 Invalid input:
1 001, 0011, 101, 10011, 1, 01, ..,
Introduction 1.28

11. Design a DFA that accepts a language, L which has the number of zeroes is of
multiples of 3.

0 Valid inputs:
0
q q q 000, 000000, 09, 012, …
0 1 2
0
1

0 0
q q q 1, 1000, 100000, …
0 1 2
0
1 1

0 0
q q q 10100, 11000, 101100, …
0 1 2
0

1 1
1
0 0 101010, 1101010, 1101110110, …
q q q Invalid inputs: 0,00,10000,01011, …
0 1 2
0

12. Design a DFA that accepts

0 1 1 1
q q q q q Valid inputs:
0 1 2 3 4 i = 1, j = 1  L = 0111

0 1 1 1 i = 1, j = 2,  L = 011111
q q q q q
0
i = 1, j = 3,  L = 01111111
1 2 3
1 4

i = 2, j = 1 L = 010111
0 1 1 1 i = 3, j = 1,  L = 01010111
q q q q q
i = 2, j = 2 L = 01011111
0 1 0 2 3
1 4
i = 3, j = 3,  L = 010101111111
1.29 Theory of Computation

1 1 Invalid inputs:
0 1
q q q q q 1, 00, 0100, 0110, 01110,
0 1 2 3 1 4 011110, 1000, 101, …
0 0
0

Q
Trap 5

0, 1

13. Design a DFA that accepts

Valid inputs:
b b
q q q bb, b5, b8, b11 [No. of b%3]
0 1 2 bb  2b’s  2% 3  2 > 1 
b bbbbb  5b’s  5% 3  2 > 1 
a bbb  3b’s  3% 3  0 > 1 

b b
q q q
0 1 2 abb, abbbbb, ab8, …
b ab2, a3b5, ...
a a

b b
q q q
0 1 2 bab, abab, aabbbbb, …
b

a a a

b b bba, bbaa, abba, abbaa, ….


q q q
Invalid inputs:
0 1 2
b b, b3, b4, b6, b7, b9, a, aa, aaa, aba,
baa, ababb
Introduction 1.30

14. Design a DFA accepting strings containing exactly one 1 over

1 Valid inputs:
q q 1
0 1
0
1
q q 01, 001, 0001, …
0 1

0 0

1
q q 10, 100, 1000, 010, 0100, …
0 1

0 0

1
q q Invalid inputs:
0 1 11
1
Trap q
2

0 0

1
q q 0110, 0101, 1111, 101,…
0 1
1

Trap q 0, 1
2
1.31 Theory of Computation

15. Design a DFA that accepts all strings with exactly two 1s over

Valid inputs:
1 1
q q q 1
0 1 2

0
1 1
q q q 011, 0011, 00011, …
0 1 2

0 0
1 1
q q q 0101, 1001, 101, …
0 1 2

0 0 0

1 1
q q q 110, 01010, 1010, 11000 ….
0 1 2

0 0 0

1 1 Invalid inputs:
q q q 111, 1110, 0111, 10101, 1111,
0 1 2
1110101, …
1

Trap q 0, 1
3

16. DFA that accepts strings containing ‘00’ as substring.


Introduction 1.32

Valid inputs:
0 0
q q q 00
0 1 2

0 0
q q q 000, 0000, 00000, …
0 1 2

1 0

0 0
q q q 100, 1100, 11000, …
0 1 2

1 0

0 0
q q q 10100, 1101100, 101101, ….
0 1 1 2

0, 1
1
0 0 Invalid inputs:
q q q
1001, 11001, 101001, …
0 1 1 2

17. Design a DFA that accepts string, such that its second symbol is zero and fourth
symbol is 1.

Valid inputs:
0 0 0 1
q q q q q 0001
0 1 2 3 4

0, 1 0 0 1 1001
q q q q q
0 1 2 3 4

0, 1 0 0 1
q q q q q 0011, 1011
0 1 2 3 4

0, 1
0, 1 0 0, 1 1 00010, 10010, 00110, 00011,
q q q q q 10011, 00111, …
0 1 2 3 4
1.33 Theory of Computation

0, 1
0, 1 0, 1 Invalid inputs:
0 1
q q q q q 0101, 0100, 0010, 1100,
0 1 2 3 4 0000, 1000, …

1 0
Trap q
5
0, 1
0, 1 0 0, 1 1
q q q q q 01010, 01000, 11111,
0 1 2 3 4 0100000, …

1 0
Trap q
5

0, 1

18. Design a DFA that accepts atmost 3 a’s.

a a a Valid inputs:
q q q q aaa, a, aa,
0 1 2 3
b
a a a
q q q q b, ba, baa, baaa, bb, bba, bbba, …
0 1 2 3
b b
a a a
q q q q bab, abba, abbbaa, babba,…
0 1 2 3
b b b
a a a
q q q q babab, aabb, aaba, bbbaaba, …
0 1 2 3
b b b b
a a a
aaabbb, aaabab, baaaba, …
q q q q
0 1 2 3
Introduction 1.34

b b b b
a a a Invalid inputs:
q q q q aaaa, aaabab, baaaba,
0 1 2 3

a

a, b q
4
Trap

19. Design a DFA that accepts all strings containing substring ‘101’.

1 0 1 Valid inputs:
q q q q 101
0 1 2 3
0
1 0 1
q q q q 0101, 000101, …
0 1 2 3
0 1
1 0 1
q q q q 011101
0 1 2 3
0 1 0, 1
1 0 1
q q q q 10100, 101, 101101, …
0 1 2 3
0
0 1 0,1
Complementary
1 0 1 [Does not accept
q q q q
substring with ‘101’]
0 1 2 3
0
1.35 Theory of Computation

20. Design a DFA to check whether a string over contains ‘abb’ is accepted.

a b Valid inputs:
b
q q q q abb
0 1 2 3
b
a b b
q q q q babb, bbabb, …
0 1 2 3
b a
a b b
q q q q aabb, baaabb, …
0 1 2 3
b a
a b b
q q q q ababb, abaabb, bababb, …
0 1 a 2 3

b a a, b
abba, abbb, abbab
a b b
q q q q
0 1 a 2 3
Invalid inputs:
ab, bbb, aaaa,abab, aaba,…

21. Design a DFA that accepts odd number of ones over

1 Valid inputs:
q q 1
0 1

1
q q 111, 11111, 17, 19, 111, …
0 1 1

0
1
q q 01, 001, 0000111, …
0 1 1

0 0
10, 1011, 10001111, 01101,…
1
q q
Invalid inputs:
0 1 1
11, 1111, 0110110, 111100110, …

0110, 0101, 1111, 101,…


Introduction 1.36

22. Design a DFA that accepts a substring “001”.

0 0 1 Valid inputs:
q q q q 001
0 1 2 3
1
0 0 1
q q q q 1001, 11001, 111001, …
0 1 2 3
1 0
0 0 1
q q q q 0001, 000001, …
0 1 2 3
1 0 0, 1
0 0 1
q q q q 00010, 110011, 110010, …
0 1 2 3
1 0 0, 1
0 0 1 101001, 10101001, …
q q q q
0 1 1 2 3
Invalid inputs:
1111, 0111, 0101, 000, …

23. Design a DFA that recognize words which do not end in ‘b’ over

a
Valid inputs:
a, aa, aaa, aaaa, …
q
0
a

b aaba, ba, aba, …


q q
0 a 1

a
b
aabbaa, bba, bbabba, …
b
q q
Invalid inputs:
0 a 1
b, bbb, abb, aabb, abab, …
1.37 Theory of Computation

24. Design a DFA that accepts exactly 4 ones over

Valid inputs:
1 1 1 1
q q q q q 1111
0 1 2 3 4
0 0 0 0 0
1 0 0 1 01111, 010100, 01010101,
q q q q q
0
1111000, 1101100, …
1 2 3 4
0 0 0 0 0
1 1 1 1 Invalid inputs:
q q q q q
0 1 2 3 4
111101, 10101011, 110111, …
1
Trap q
5
0 0 0 0 0
1 1 1 1 1111010, 1111011, …
q q q q q
0 1 2 3 4

1
q
0, 1
5

Extended transition function: Delta Cap/Hat

 The extended transition function, takes two parameters, state and string.

 It is a mapping from

 Formally cann be defined as


Introduction 1.38

PROBLEMS
1) Consider the transition diagram

b a a, b
a b
q q q
0 1 2

Check whether the input string,”aab” is accepted by the finite automata.

Final state

Hence the given string “aab” is accepted by FA.


2) Consider the FA
a
a

b
q q
0
b 1

Show how the string and is processed.

1)
1.39 Theory of Computation

Final state string is accepted

2)

Not a final state string not accepted

3) Check whether the strings “ababba” ,”baab” are accepted by the DFA?
AU – May / June, Nov / Dec 2009

a b

a
q q q
0 1
a, b 2

1)
Introduction 1.40

Not a Final state Not accepted

2)

Final state string accepted

1.5 NON DETERMINISTIC FINITE AUTOMATA


AU - Nov/Dec 2013
A NFA has 5 tuples defined as,

M=
1.41 Theory of Computation

where,
Q a finite set of states
A finite set of inputs

Transition function from

Start / initial state

F A set of final / accepting states

Subset

Difference between DFA and NFA

S.NO DFA NFA


1. The transition is deterministic The transition is non-deterministic
2. It has more number of states than It has less number of states.
NFA
3. It provides only one state transition It may lead to more than one states for
for a given input given input
4. It has only one final state It has more than one final states
5. More difficult to design It is easy to design
6. It has a single path for an input It may have several paths for a single
from a state input from a state. Backtracking is
required.

PROBLEMS

1) Sketch the NFA state diagram for M = with given as

∑ 0 1
Q


Introduction 1.42

*
Solution

0, 1 0, 1
0 q 0
1
q q
0 3

1 1
q
2

2) Design a NFA with no more than five states for the set .

a b a
q q q q
2
0 1
a 3

a
q
4

3) Determine a NFA that accepts .

a
a a, b
q q q
0 1 2

4) For NFA shown, check whether ‘0100’ is accepted or not.


0 1

0
q q
0 1
1
0
1 1
q
2

0
1.43 Theory of Computation

∑ 0 1
Q

*
Solution:

Since q0 is final state string accepted


Introduction 1.44

5) NFA with states and has as,

Calculate 1)

2)

∑ a b
Q

1

5
Solution:

1)
1.45 Theory of Computation

2) :

6) Design a NFA to accept strings containing the substring,”0101”.


0, 1 0, 1
0 1 0 1
q q q q q
0 1 2 3 4

NFA: where,
Introduction 1.46

is given as

∑ 0 1
Q

7) Construct a NFA that accepts

a, b
a a b
q q q q
0 1 2 3

∑ a b
Q

is given as
*
1.47 Theory of Computation

8) Design a NFA to accept strings over alphabet , such that the third symbol from
right end is 0.
0, 1
0 0, 1 0, 1
q q q q
0 1 2 3

The transition function, is given as


0 1
Q

9) Construct a NFA for L = contains exactly one b immediately

following c}.
Introduction 1.48

a, b a, b, c
c a, c
q q q
0 1 1
1 b
a Trap
b

q
4

10) Construct a NFA that accept L = is starting with 1 and is divisible by

3}.

0, 1

q Trap
0 4

q
1
1 0, 1
q q
1 2
0, 1

0, 1
q
3

11) Design a NFA for L = contains any number of a’s followed by atleast
one b .

a b a, b

b a
q q q
0 1 2

Trap

12) Design a NFA for a binary number where the first and the last digits are same.
1.49 Theory of Computation

0, 1

0
q q
0 2 4

q
1
1 1
q q
3 5

0, 1

13) Construct a NFA over such that each ‘0’ is immediately preceded and
immediately followed by 1.
1

1
q q
0 1

0 1
0

0
q q
3 2
0, 1
Trap

14) Construct NFA for the RE: (0+1)01.

0,1
0 1
q q q
0 1 2

1.6 EQUIVALENCE OF DFA AND NFA


Every language that can be described by some NFA can also be described by some DFA. It
involves subset construction process for conversion.

Let be the given NFA.

We can construct DFA,


Introduction 1.50

D=

where,
Set of all subsets of

Set of subsets,S of such that

For each set, S contained in , i.e., and each input a in be


defined as

Procedure

1. If , then create subsets,


and . Thus if no of states = n; the no of subsets =2n.

2. Construct the transition table for the subsets over the given language, .

3. Minimise the table by considering only the reachable states from the start state.

4. Draw the DFA from the minimised transition table.

PROBLEMS

1) Construct a DFA from the following NFA that accepts all strings of 0’s and 1’s that
end with ‘01’. AU - NOV/DEC 2013, NOV/DEC 2003, MAY/JUNE 2006

Solution:
NFA

0,1
0 1
q q q
0 1 2

Here ,

∑ 0 1
Q

*
1.51 Theory of Computation

Subsets

Transition table:


0 1
Q

*
*
Minimised transition table

∑ 0 1
Q

 Processed

Processed
*
Introduction 1.52

both are processed


Minimised DFA
1 0

0 1
{q 0 } {q 0 , q1} {q 0 , q 2 }

0
1

2) Convert the given NFA to DFA.


0 1
Q

s
*
NFA for the above specification

0, 1 0, 1

0 0, 1 0, 1
p q r s

Subsets

p, r, p,sq, r, q,s, r,s,


1.53 Theory of Computation

Transition table
∑ 0 1
Q

*
Minimised transition table

* 0 1
Q
*

*

DFA

*
Introduction 1.54

0 0
{p} {p, q} {p, q, r}

1 0
1
1 0
{p, r} {p, q, r,s}

0
0 1
1
{p, q,s} {p, r,s}
0
0 1
{p,s}
p,s
1
3) Convert the following NFA to DFA. AU NOV/DEC 2004


0 1
Q

*s

Solution
Here,
1.55 Theory of Computation

0, 1 0, 1 0
p r r s

1 1
1

Subsets


0 1
Q
Transition table

*
*

*
*

* *

*
Introduction 1.56

Minimised transition table:

∑ 0 1
Q

*
DFA diagram
1

1
{q,s} {p, q, r}
0 0

1
{p {r} 0 1 {r,s}
} 1 0 1
0
1 1 {q, r,s}
{q
} 0
1 {q, r}
{s} 0
0

4. Construct a DFA for the following NFA. AU MAY/JUN 2009


1.57 Theory of Computation

0 1
q q q
0 1 2

0 1
Solution
QN = {q0, q1, q2}
∑ = {0, 1}
q0 = {q0}
FN = {q2}


0 1
Q

 {q0} {q0, q1} 


{q0}  {q2}

* {q2}  {q2}
Construction of DFA

QD = {, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, {q1, q2}, {q0, q1, q2}}
FD = {{q2}, {q0, q2}, {q1, q2}, {q0, q1, q2}}
q0 = {q0}
Transition table


0 1
Q

  
{q0} {q0, q1} 
{q1}  {q2}
*{q2}  {q2}
{q0, q1} {q0, q1} {q2}
*{q0, q2} {q0, q1} {q2}
*{q1, q2}  {q2}
{q0, q1, q2} {q0, q1} {q2}
Introduction 1.58

Minimized transition table


0 1
Q

 {q0} {q0, q1} 


{q0, q1} {q0, q1} {q2}
* {q2}  {q2}
Minimized DFA
1
0

0 1
{q 0 } {q 0 , q1} {q 2 }

5. Convert M = ({q1, q2, q3}, {0, 1}, {q1}, {q3}), where  is given by,

 (q1, 0) = {q2, q3}  (q1, 1) = {q1}

 (q2, 0) = {q1, q2}  (q2, 1) = 

 (q3, 0) = {q2}  (q3, 1) = {q1, q2}


Construct an equivalent DFA
Solution
Given NFA,

1 0
0
0 0,1
q q q
1 0 2 3


0 1
Q

q1 {q2, q3} {q1}


q2 {q1, q2} 
* q3 {q2} {q1, q2}
1.59 Theory of Computation

DFA construction
∑ = {0, 1}

QD = {, {q1}, {q2}, {q3}, {q1, q2}, {q1, q3}, {q2, q3}, {q1, q2, q3}}
q0 = {q1}
FD = {{q3}, {q1, q3}, {q2, q3}, {q1, q2, q3}}
Transition table

∑ 0 1
Q
*   

{q1} {q2, q3} {q1}
*
{q2} {q1, q2} 
*
{q3} {q2} {q1, q2}
*
{q1, q2} {q1, q2, q3} {q1}
Minimized {q1, q3} {q2, q3} {q1, q2} DFA table

{q2, q3} ∑ {q01, q2} {q


1 1, q2}
{q
Q 1, q2, q3} {q1, q2, q3} {q1, q2}

 {q1} {q2, q3} {q1}


{q2, q3} {q1, q2} {q1, q2}
{q1, q2} {q1, q2, q3} {q1}
* {q1, q2, q3} {q1, q2, q3} {q1, q2}

Minimized DFA
Introduction 1.60

0
1

0 0,1 0
{q1} {q 2 , q 3 } {q1 , q 2 } {q1 , q 2 , q 3}

1
1

THEOREM AU – MAY 2005, DEC 2006, DEC 2013


A Language, L is accepted by some NFA if and only if it is accepted by some DFA
(or)
For every NFA, there exists an equivalent DFA
Proof
This theorem has two parts:-
1) If L is accepted by a DFA (M2), then L is accepted by some NFA (M1)
2) If L is accepted by a NFA (M1), then L is accepted by some DFA (M2)
To prove the theorem, it is enough to prove that

For an arbitrary string w, we prove this statement, we use induction principle on .


Basis of Induction
Let =0

Then w = ε
By the definition of extended transition function,

----- (1)

----- (2)
is true for w = Є Hence proved that L [D] = L [N].
Inductive step
Let us assume that the theorem is true for all the strings, w of length ‘n’. (i.e.) .
Now let us prove that the same is true for a string of length, n+1
Let w = xa, where
a → last symbol of w.
1.61 Theory of Computation

By assumption, we have,

Now, by the definition of extended transition function of DFA,

=
By induction principle, the theorem is true for all the strings, w of the given
language.
Thus, L [D] = L [N]
1.7 NFA WITH Є TRANSITIONS
The Є [Epsilon] used to indicate null string. The string is used for transition from one
state to other without any input. AU DEC 2007

Formal Notation for Є – NFA


A non deterministic FA, M with Є –transition is given by E = (Q, ∑, δ, q0, F), where
Q →finite set of states
∑→finite set of input alphabets
q0 → Initial/ start state
F → F Q →set of final/accepting states
δ → Transition/ Mapping function from
Q X {∑ U {Є}} → 2Q
EPSILON CLOSURE AU MAY 2012, DEC 2010, MAY 2013
Epsilon closure of a state, q is defined as the set of states reachable from q on Є moves. Є -
closure of q0 is denoted as ЄCLOSE (q0).
Example: Obtain Є closure of each state in the following Є – NFA with Є – move.
AU DEC 2005
Introduction 1.62

 
q q q
0 1 2

0 0 2
Є CLOSURE {q0} = {q0, q1, q2}
Є CLOSURE {q1} = {q1, q2}
Є CLOSURE {q2} = {q2}
2) Find Є- CLOSURE of States 1,2 and 4 from the following transition diagram. AU
MAY 2008
Є Є
3 6
2
Є

1 Є
a 7
4 5
Є

Є –Closure {1} = {1,2,4,3,6}


Є –Closure {2} = {2,3,6}
Є –Closure {4} = {4}
Eliminating Epsilon transitions
Given any epsilon NFA with Є moves, we can find a DFA that accept the same language as E.
Let E = (QE, ∑,δE, qE, FE)
Then the equivalent DFA,
D = (QD, ∑,δD, qD, FD) is defined as follows.
(i) QD is the set of subsets, s of QE. S QE such that s= ECLOSE (S)
(ii) qD = ECLOSE(qE)
(iii) FD = {s / s is in QD and S n FE ≠ }
(iv) δD(s,Q) is computed for all a in ∑ and sets, S in QD by
a) Let S = P1, P2,….,Pk)
1.63 Theory of Computation

b)

c)

PROBLEMS

1) Design a DFA that eliminates Є transition from the following Є- NFA.


Є a b c d
QE

q0 q0, q1

q1 q1 q1, q2 q3

q2 q2, q3 q2 q2

*q3 q3 q3 q3

a c,d

Є a
q0 q1 q2

b Є

q3

a,b
Solution
Start state of DFA
ECLOSE (q0) = {q0, q1} → Start State of DFA
Successors of {q0, q1} for the input symbols, {a,b,c,d}
Introduction 1.64

Successors of for the input symbols {a,b,c,d}


1.65 Theory of Computation
Introduction 1.66

Successors of for the input symbols,{a,b,c,d}.

Successors of over the input symbols {a,b,c,d}


1.67 Theory of Computation

Transition Table


a b c d
QD

{q0,q1} {q1,q2,q3} {q3}

{q1,q2,q3} {q1,q2,q3} {q3} {q2,q3} {q2,q3}


Introduction 1.68

* {q3} {q3} {q3}

{q2,q3} {q3} {q3} {q2,q3} {q2,q3}

Equivalent DFA

a
{q 0 , q1} {q1 , q 2 , q 3}

b b
c, d

{{q3}
{q3 {q 2 , q 3}
a, b } a, b c, d

2) Design a DFA that eliminates Є transitions from the following Є-NFA.

Solution
Start of DFA
ECLOSE(q0) ={q0, q1} ∑
Є a b c d e
↓ QD

Start q0 q0, q1 State of DFA


Successors of {q0, q1} q1 q1 q1 q4 q2 over ∑={a,b,c,d,e}
q2 q2 q2 q3

q3 q3, q5 q3

q4 q4, q5 q4 q2

*q5 q5

a d e

Є C e
q0 q1 q2 q3

Є
b C
q0 Є
q
5

1.69 Theory of Computation

Successors of {q1} over ∑ = {a, b, c, d, e}:-


Introduction 1.70

Successors of {q4,q5} over ∑ = {a, b, c, d, e}


1.71 Theory of Computation

Successors of {q2} over ∑ = {a, b, c, d, e}


Introduction 1.72

Successors of {q3, q5} over ∑ = {a, b, c, d, e}


1.73 Theory of Computation

TRANSITION TABLE

∑ a b c d e
QD
{q0,q1} {q1} {q4,q5} {q2}

{q1} {q1} {q4,q5} {q2}

{q4,q5} {q4,q5} {q2}

{q2} {q2} {q3,q5}

*{q3,q5} {q3,q5}

DFA – Transition Diagram

a
{q 0 , q1} {q1}

b
b c e

c
{q4, {q 2 , q 3 } {q3,
q5} q5}
a
d

3) Consider the following Є – NFA


Introduction 1.74

∑ Є a b c

QE

p {q,r} {q} {r}

q {p} {r} {p,q}

*r

a) Complete the Є – closures of each state


b) Convert the automation to DFA
Solution:-

a)  – closure of states

State - Closure

p {p,q,r}

q {q}

r {r}

b) Є NFA → DFA
Start state of DFA, qD
ECLOSE (P) = {p, q, r}
Successors of {p, q, r} over ∑ = {a, b, c}
1.75 Theory of Computation

Successors of {q, r} over ∑ = {a, b, c}


Introduction 1.76

Successsors of {r} over ∑ = (a,b,c).

Transition Table

a b c
QD

{p,q,r} {p,q,r} {q,r} {p,q,r}

{q,r} {p,q,r} {r} {p,q,r}

* {r}

Transition diagram
1.77 Theory of Computation

b
{p,q,r {q,r
} a,c }

{r
} 

1.8 REGULAR LANGUAGES AND REGULAR EXPRESSIONS

The languages accepted by a finite automation can easily be described by a simple expression
called Regular Expressions.
Regular Expressions serve s the input language for many systems that process strings Regular
expression uses a set of operators (like +,., *,….) to represent the language.
Search systems convert RE into DFA/NFA that stimulates the automation on the file being
searched.
Example: Lexical Analyzer accepts tokens as inputs and produces a DFA that recognizes
which token appears next on the input. The set of Stings accepted by finite automata is known
as regular language.
Representation

DFA Language Regular Expression

{Є} R.E = ε

{a} R.E = a

b {a, b} R. E = a + b

a b
{ab} R.E = a.b = ab

Formal Definition of a RE
Introduction 1.78

Let ∑ be a given alphabet. Then,


(i) , , and a belongs to ∑, are all regular expressions. [primitive Regular Expressions]
(ii) If r1 and r2 are regular expressions, then r1+r2, r1r2, r1*, (r1) are also regular
expression if and only if it can be derived from the primitive RE by the finite
number of applications of the rules in (ii).
Operators of Regular Expressions
The union of two languages, L and M is denoted by LUM which are a set of strings that are
either in L or M or both.
Example:
L = {001, 10, 111}
M = {, 001}
LUM = {, 00, 10,111}
The concatenation of languages L and M, denoted L.M which are a set of strings that can be
formed by taking any string in L and concatenating with any string in M.
Example:
L = {001, 10, 111}
M = {, 001}

LM = {001, 001001, 10, 1000, 111, 111001}


The closure of a language, L is denoted as L* represent the set of those strings that can be
formed by taking any number of strings from L, possibly with repetitions and concatenating
all of them.
Example:
L = {0, 1}

L0 = {}

L1 = {0, 1}
L2 = {01, 00, 11, 10}
PROBLEMS
1) What is {10, 11}*? Write atleast first seven terms. AU DEC 2009
(10, 11)* = (10, 11)) U (10, 11)’U (10, 11) 2 U (10, 11) 3 U…..

= {} U {10, 11} U {1011, 1110} U {101110, 101011,…}


1.79 Theory of Computation

= { , 10, 11, 1011, 1110, 101110, 101011,….}

2) Write a RE for the language accepting all combinations of a’s over the set ∑ = {a}
L = {all combination of a’s over {a}}
= {Є, a, aa, aaa,…….}
R = a*
3) Design the RE for the language accepting all combinations of a’s except the null string
over
{}

L = {all combination of a over {a }except }


= {a, aa, aaa,aaaa…….}
R = a+
4) Design a RE for the languages containing all thes strings containing any number of
a’s and b’s .

L = { a,b, aa, bb, ab,aab,….}


R = (a+b)*
5) Construct the RE for the language contai9ning all strings having any number of a’s
and b’s except the null string.
L = {a, ab, b, aa, abb, aabb ,..}
R = (a+b)+
6) Construct a RE for the language accepting all strings which are ending with 00 over
the set, ∑ = {0,1}
L = {00, 000, 100, 0100, 1000, 01000, 01000, 11100,..}
R = (0+1)* 00.
7) Write a RE for the language accepting the strings which are starting with 1 and
ending with 0, over the set ∑ = {0,1}
L = {10, 100, 110, 1000, 10101, 111000 ….s,}
R = 1(0+1)*0
8) Write a RE to denote a language, L over ∑* where ∑ = {a, b} that the third character
from right end of the string is always a.
Introduction 1.80

L = aab, aba, aaa, abb, babb, aaaa,…


R = (a+b)* a(a+b)(a+b)
9) Construct a RE for the language, L which accepts all the strings with at least 2 b’s
over the alphabets ∑ = {a,b}
L = {bb, abb, bba, bab,bbb,bbaa, ababa,…}
R =(a+b)*b(a+b)*b(a+b)*
10) Construct a RE for the language which consist of exactly 2 b’s over the set, ∑ = {a, b}
L = {bb, abb, baba, bba, aaaabab,….}
R = a*ba*ba*
11) Construct a RE which denotes a language, L over the set , ∑ = {0}, having even length
of string.

L = {00,, 0000, 000000,…}

R = (00)*
12) Write a RE which denotes a language, L overt the set, ∑ = {1}, having odd length of
strings
L = {1, 111, 11111, 1111111,…}
R = (11)*1
13) Write the RE to denote the language, L over ∑ = {a, b}, such that all the strings do
not contain the substring ab.
L = {bbaa, ba, bbbaaa, bb, aa,….}
R = b* a*
14) Write a RE which contains L having the strings which have at least one 0 and 1.
L = {01,001,101,010,011, 10101,10,..}
→ R = (0+1)* 0(0+1)* 1(0+1)* + (0+!)* 1(0+1)*0(0+1)*
15) Describe the following by RE
a) L1 = the set of all strings of 0’s and 1’s ending in 00.
b) L2 = the set of all strings of 0’s and 1’s beginning with 0 and ending with 1
AU MAY 2004
1.81 Theory of Computation

a) R1 = (0+1)* 00
b) R2 = 0(0+1)* 1
16) Find the RE for
a) The language of all strings containing exactly two 0’s
` b) The language of all strings containing at least two 0’s
c) The language of all string that do not end with 01.
Solution
a) R1 = 1* 0 1* 0 1*
b) R2 = 1* 0 1* 0 (1+0)*
c) R3 = (1+0)* (00 + 11 + 10)
1.9 CONVERTING DFA TO RE

THEOREM
If L is a language defined by some DFA, then there is a regular expression defining L.
(or)
If L = L(A) for some DFA, then there is a RE, R such that L = L [R]
PROOF
Let a be a DFA which defines a language L Assume that A has ‘n’ states.

Let us construct the RE of the form, , whose language is the set of strings, w that takes
the DFA from state I to j without going to any state, numbered greater than k.

We construct by induction, k as follows

Basis
Let k = 0 [since all the states are numbered 1]. The Restriction on paths is that the path must
have no intermediate states at all.
There are only two kinds of paths that need such a condition,
 An arc from state I to state j.
 A path of length zero, that consists of only some state i.
Case 1:- if i≠j
Introduction 1.82

Only (i) is possible. We must examine the DFA, A and find those input symbol, a
such that there is a transition from state, I to j on symbol, a

a) If there is no such symbol, a then =

b) If there is exactly one such symbol, a then =a

c) If there are symbols a1, a2,….ak that label arcs from state i to j then = a1 + a2
+ a3 + …. + ak
Case 2:- if i = j
The legal paths are the path of length zero and all loops from I to itself.
The path of length zero is represented by the regular expression,  since the path has
no symbols along it. Thus we add, Є to the various expressions derived in (a) through (c)
above.
i.e., Case (a) → No symbol ‘a’ → The expression becomes .
Case (b) → One symbol ‘a’→ The expression becomes +a
Case (c) → Multiple symbols ‘a’→ The expression becomes  + a1 + a2 +a3 +….+ ak
Induction
Suppose there is a path from state i to state j that goes through no state higher than K.
There are two possible cases to consider.
Case 1
The path does not go through state k at all. In this case, the label of the path is in the
language of

Case 2
The path goes through state k at least once. Then we can break the path into several pieces.
The first goes from state I to state k without passing through k.
The Last piece goes from k to j without passing through k and all the pieces in the middle go
from k to itself without passing through k. If a path goes through state k only once, then there
are not middle pieces just a path from I to k and a path from k to I.
The set of labels for all paths of this type is represented by the regular expression
, i.e., the first expression represents the part of the path that gets to state k,
the first time, the second represents the quotient that goes from k to itself ‘0‘ times, once or
more than once. And the third expression represents the part of the path that leaves k for the
last time and goes to state, j.
When we combine the expressions for the paths of the two types, we have the expression
1.83 Theory of Computation

Therefore, by induction hypothesis, we can conclude that the RE can be constructed for
all values of I,j and n. The RE for the language defined by the DFA is the sum of all
expressions of all expressions such that state j is an accepting state.

Some simple results of RE

PROBLEMS

1) Obtain the RE that denotes the language as accepted by the


following DFA.
AU DEC 2004
1 0,1
0
1 2

Solution: To find

i → start state = 1

j → Final state = 2
Introduction 1.84

k → 0 to n [n→no of states] = 0,1,2

So, we have to find

Basis Step

Step 1:

i takes the values 1,2

j takes the values 1,2

Inductive Step

k takes the values 1 and 2. For k =0, basis step has already been calculated.

Step 2:

k=1

i=1; j=1
1.85 Theory of Computation

i=1; j=2

i=2; j=1

i=2; j=2:-

Step 3:

k=2

To find
Introduction 1.86

i=1; j=2

The Required regular expression is

2) Construct a RE corresponding to the state diagram given in the following figure.


AU MAY 2005
0

1 0
q1 q2 q3
1

0 1
Solution
Here;
i=1
j=1
k=3

To find:

Basis
Step 1:
1.87 Theory of Computation

Inductive step

k=0 computed in step 1

k = 1, 2, 3 computed in step 2, 3 and 4

i takes the values 1, 2, 3

j takes the values 1, 2, 3.

Step 2:

k=1
Introduction 1.88
1.89 Theory of Computation

Step 3:

k =2

To find:

So at k = 2; it is enough to find
Introduction 1.90

Step 4:
k=3

To find:

The Required Regular Expression is given as,

3) Obtain a Regular Expression that denotes the language accepted by

AU MAY 2005, DEC 2006, DEC 2009


1

0 q 1
q1 q3
1

0
0,1
Solution

To find:

i = 1 ←Initial State.
j = 2 ← Final state
k = 3 ← No of states.

Basis
Step 1:
1.91 Theory of Computation

Inductive step

i takes the values 1,2,3

j takes the values 1,2,3

k takes the values 0,1,2,3

Step 2:

k=1
Introduction 1.92

Step 3:

k=2
1.93 Theory of Computation

To find :

At k = 2; It is enough to find
Introduction 1.94

Step 4:

k=3

4. Find the RE, from the following DFA. AU DEC 2007

1
1
1 2 1 3
0

Solution

To find:

Basis

Step 1:

Inductive Step

We Require

Step 2:
1.95 Theory of Computation

k=1

Step 3:

k=2

R.E.

5. Find the language accepted by the following automaton

q1 1 0
q2 q3

0,1
0 1

Solution

The language accepted by the above DFA is [since there are two final states]

The state q3 is eliminated since it is a trap/dead state.


Introduction 1.96

0 1

1
q1 q2

Basis

Step 1:

Step 2:

k=1

It is enough to find
1.97 Theory of Computation

Step 3:

k =2
Introduction 1.98

The R.E

1.10 CONSTRUCTING DFA BY ELIMINATING STATES

Consider the following setup in which the state ‘S’ is to be eliminated.

Rij
qi pj

Qj
Pj

Assume that the state, qi is predecessors of the state S. P j is the successor of s. When we
eliminate the state s, the regular expression, is labeled to R from Q i to Pj. Note that Qi and Pj
may also be same.

The construction of a R. E. from F.A. is as follows:


(i) For each accepting state Q, eliminate all states except Q, on the start state q0. By
applying the above reduction process to produce an equivalent automataton with
regular expressions labels on the arcs.
(ii) Suppose, if i.e., accepting state and start state are distinct, then finally we
have two state automaton.

R
U

q0 S
q
T

We can represent the accepting string of this two-state automaton in many ways. In general,
we take the string accepted by this automaton, of the form;
1.99 Theory of Computation

(iii) If the start state and the accepting state are the same, then we are left with one –
state automaton.

q0

The regular expression denoting the language that it accepts is, R*

(iv) The derived regular expression is the sum of all expressions from the reduced
automaton for each accepting states by rules (ii) and (iii)
PROBLEMS

1) Construct the transition diagram for the given DFA and give a R.E by using state
elimination technique.


0 1
Q

q1 {q2} {q1}

q2 {q3} {q1}

* q3 {q3} {q2}

1 0
0

1 0
q1 q2
q
1 3

Solution

Here, q1 → Start State

q3 → Final State
Introduction 1.100

The state to be eliminated is q2.

We use the Regular Expression: is labeled for the arcs from q1 to q3.

To be found

 q1-q2-q3

 q3-q2-q1

 q1-q2-q1

 q3-q2-q1

Step -1:- Eliminating q2 from q1-q2-q3

Rij

q1 ___ q2 ___ q3

Qi Pj
Here, S

Rij = 

Qi = 0

S=

Pj = 0

Step 2: Eliminating q2 from q3 – q2 – q1

Rij
Rij = 
1.101 Theory of Computation

q3 - q2 - q1 Qi = 1

Qi S= 
Pj

S Pj = 1

r2 =  + 1 * 1

=  + 11 ←  * = None

r2 = 11 ←+a=a

Step 3: Eliminating q2 from q1 - q2 – q1

Rij = 0
Rij
Qi = 1

q1 - q2 - q1 S =

Pj = 0
Qi Pj
S
Step 4: Eliminating q2 from q3 - q2 - q3

Rij = 0
Rij
Qi = 1

q3 - q2 - q3 S = Ǿ

Qi Pj = 0
Pj
S

r4 = 0 + 1. * . 0

r4 = 0 + 10 ← * = None

The $ Two – State Automaton:-

00
1+01 0 + 10 R
S U

q1 q1
q q
11 3
T 3
Introduction 1.102

The R.E = ( R + SU* T)* SU*

R.E = ((1 + 01) + (00) (0 + 10)* (11))* 00 (0 + 10

2) Convert the following DFA to RE using state elimination technique.


0 1
Q
*p s p

q p s

r r q

s q r

1 0

P 0 1 1
q r s
1

Solution

[First eliminate the state that is far away from start state].

States to be eliminated: s, r, q

Initial / start state = Final start = P cannot be eliminated

R.E = Rij + QiS* Pj

To find:


1.103 Theory of Computation

Step 1:

Elimination of s from p - s - q (r1)

Rij
Rij = 

p - s - q Q1 = 0

Qi Pj S=

Pj = 0
S

Elimination of s from q - s - p (r2)

Rij = 0
Rij
Qi = 1

q - s - p S =
Pj Pj = 
Qi
S
Introduction 1.104

Eliminating s from p - s - r (r3)

Rij

p - s - r

Qi Pj
S

Elimination of s from r- s- p (r4)

Rij

r - s - p

Qi Pj
S

Elimination of s from q – s – r (r5)

Rij

q - s - r

Qi Pj
S

Elimination of s from r – s- q (r6)

Rij
Pj

r - s - q

Qi Pj
1.105 Theory of Computation

Elimination of s from p – s – p (r7)


Rij

p - s - p

Qi Pj
S

Elimination of s from q – s – q (r8)

Rij

q - s - q

Qi Pj
S

Elimination of s from r – s- r (r9)

Rij

r - s - r

Qi Pj
S

Reduced Automaton
Introduction 1.106

10
1 0
00 11
P q r
1
0
01

Step 2: Elimination of ‘r’.

 r1 : p – r – q
 r2 : q - r - p
 r3 : p – r – p
 r4 : q – r – q
Elimination of r from p – r- q ( r1)
Rij

p - r - q

Qi Pj
S

Elimination of r from q – r – p (r2)

Rij

q - r - p

Qi Pj
S

Elimination of r from p – r –p (r3)

Rij

p - r - p

Qi Pj
1.107 Theory of Computation

Elimination of r from q – r- q (r4)


Rij

q - r - q

Qi Pj
S

The Reduced Automaton is given as

00 + 01(0)*1
1
10 + 11(0)*1

p q

Step 3: Elimination of ‘q’

Elimination of q from p – q – p (r1)


Rij

p - q - p

Qi Pj
S

The Reduced Automaton is given as

1 + (00 + 01(0)* (10 + 11(0)*)*0

The RE = r*

R = [ 1 + (00 + 010*1) ( 10 + 110*1) * 0]*


Introduction 1.108

3) Convert the following NFA that accepts all strings of 0’s and 1’s such that either the second or
third position from right end has 1 to a R.E using state elimination technique.

AU NOV/DEC 2013

0, 1

A 1 B 0, 1 0, 1
C D

Solution
Eliminate B. A → Start state cannot be eliminated
C, D → Final states cannot be eliminated first
To find:
Elimination of state B
 r1 : A – B - C
 r2 : C – B - A
 r3 : A – B - D
 r4 : D – B - A
 r5 : A – B - A
 r6 : C – B - C
 r7 : D – B - D
 r8 : C – B - D
 r9 : D – B – C

Step 1:

Elimination of state – B can be done using

Eliminating B from A – B – C (r1)

A - B - C

Qi
Pj
S
1.109 Theory of Computation

Eliminating B from C – B – A (r2)

Rij

C - B - A

Qi Pj
S

Eliminating of B from A – B – D (r3)

Rij

A - B - D

Qi Pj
S

Eliminating B from D – B – A (r4)


Rij

D - B - A

Qi
Pj
S

Eliminating B from A – B – A (r5)

Rij

A - B - C

Qi Pj
S
Introduction 1.110

Eliminating B from C – B – C- (r6)

Rij

C - B - C

Qi Pj
S

Eliminating B from D – B – D (r7)


Rij

D - B - D

Qi Pj
S
Eliminating B from C – B – D (r8)

Rij

C - B - D

Qi Pj
S

Eliminating B from D – B – C (r4)

Rij

D - B - C

Qi Pj
S

Reduced Automaton
1.111 Theory of Computation

0+1
1 ( 0 + 1)
0+1
A C D

Step 2:

Case – 1: Eliminating of ‘C’

 r1 : A - C - D
 r2 : D - C - A
 r3 : A - C - A
 r4 : D - C - D

Elimination of C from A – C – D (r1)

Rij

A - C - D

Qi Pj
S

Elimination of C from D – C – A (r2)

Rij

D - C - A

Qi
Pj
S

Elimination of C from A – C – A (r3)

Rij
r1 :

A - C - A

Qi Pj
S
Introduction 1.112

Eliminating C from D – C – D:- (r4)

Rij
r1 :

D - C - D

Qi
Pj
S

Resulting Automaton

0, 1
1(0+1) (0+1) R U
S
A D
1 2
T

Regular Expression (RE1) = (R + SU*T)* SU*

= ((0+1) + (1(0+1) (0 +1) (Ǿ)*Ǿ)*

= (1(0+1) (0+1) Ǿ*)

= ((0+1) + Ǿ)* (1(0 + 1) (0+ 1))

= (0+1)* (1 (0 + 1) (0+ 1))

Case – 2: Elimination of D from Automation obtained from step – 1

A - C - D

D - C - A

A - C - A
Eliminating D from A- D – C (r1)
Rij

A - D - C
1.113 Theory of Computation

Qi Pj
S

Eliminating D from C – D – A (r2)


Rij

A - D - C

Qi Pj
S

Eliminating D from A – D – A (r3)


Rij

A - D - A

Qi Pj
S

Eliminating D from C – D – A (r4)


Rij

C - D - A

Qi Pj
S

The Reduced Automaton

0+1 R
1 (0+1)
S U
A C
c 1 2
c T
Regular Expression (RE1) = (R + Su*T)*
c SU*
RE1 = (0+ 1) + (1 (0 + 1)) * )* (1 (0 + 1)) *
Introduction 1.114

RE2 = (0 + 1) * 1 (0 + 1)
Final Automaton
R = RE1 + RE2
= (0 + 1)* 1(0+1)(0 + 1) + ( 0 + 1)* 1( 0 + 1)

1.11 CONVERTING R.E TO AUTOMATA

THEOREM

Every language defined by a regular expression is also defined by definite automata

(or)

Let ‘r’ be a regular expression, then there exists a NFA with Є – transition that accepts L (r).

Proof

Suppose L = L[R] for a regular expression, R. we show that L = L[E] for some  – NFA, with
(i) Exactly one accepting state.
(ii) No arcs into the initial state.
(iii) No arcs out of the accepting state.
Structural Induction on R
Basis

Є
(a) r = 

(b) r = 

a
(c) r = a

In (a) → the RE,  is handled. The language = {}, since the only part from the start state to
the accepting state, labeled Є.

In (b) → It shows the construction of  clearly there are no paths from start state L = {}
1.115 Theory of Computation

In ( c) → It gives the automaton for a RE ,’a’. The language of their automaton evidently
consists of the one string, ‘a’ which is also L [a]. These automaton satisfy conditions (i), (ii),
(iii) of the induction hypothesis.
Inductive Step
Assume that the theorem is true for the immediate sub-expressions of a given regular
expression. The languages of Є- NFA’s with a single accepting state.

 The expression is R + S for some smaller expression R and S.

 It starts at a new state, can go to the start state of either R or S, and then reach the
accepting state of one of these automata following a path labeled by some string L[R]
or L[S] respectively.

 Once we reach the accepting state of the automaton for R or S.

Є
Є
Є

(a) R + S

Є
Є
Є

 We can follow one of the Є – arcs to the accepting state of the new automaton.

 Thus the language of this automaton is L [R] U L [S].


(b) R.S

R Є S

 The expression is R. S for some smaller expression R and S.

 The start state of the first automaton becomes the start state of the whole and the
accepting state is the accepting state of the whole.

 The idea is that the only paths from start state to accepting state, go first through the
automaton for R where it must follow a path labeled by a string in L[R], and then
prove the automaton for S where it follows a path labeled by a string in L [S].

 Thus the language is the concatenation of two regular expressions, L[R] L[S].
Introduction 1.116

(c) R*

Є R Є

 The expression is R* for some smaller expression, R.

 This automaton allows is to go either:

o Directly from the start state to the accepting state along a path labeled . That
path  which is in L [R*] doesn’t matter what expression R is.
o Goes to the start state of the automaton for R and processes through that
automaton one or more times and then to the accepting state. This set of paths
allows us to accept strings in Є, L[R], L[R]L[R], L[R]L[R]L[R and so on.

 Thus covering all strings in L[R*] except perhaps  which was covered by the direct
arc to the accepting state mentioned in (c)
(d) The expression is (r) for some smaller expression, R.

 The automaton for R also serves as the automaton for (r).

 Since the parenthesis does not change the language defined by the expression.

 It is a simple observation that the constructed automaton satisfies the three


conditions given the inductive hypothesis, one accepting state with no arcs into the
initial state or out of the accepting state.
PROBLEMS

1) Convert the RE: (0 + 1)* 1(0+1) to -NFA


(0+1)
1.117 Theory of Computation

0
2 4 Є
Є

6
1
1
Є 3 5 Є

(0+1)*

0
Є
3 5 Є

7 8
Є
1 2 Є
1
Є 4 6

(0+1)*1

0
Є
3 5 Є Є 1
8 9 1
Є 7
0
1 2 Є
1
Є 4 6

(0+1)* 1(0+1)
Introduction 1.118


0
0 1 1
1 3 Є

3 5 Є Є 1
Є 1
Є 1
Є 7 8 9 1
5
1 2 Є Є
0
0
1 1
4 6 Є 1 1 Є
2 4

Є Є

2) Convert the RE: 01* to -NFA


0
0
1 2

1*
Є

Є 1 Є
1 2 3 4

01*
Є

Є Є Є 1 Є
1 2 3 4 5 6

3) Convert the RE:- (0+1)0 to – NFA


1.119 Theory of Computation

0
Є
Є 2 4
Є 0
6 7 8
1
1
Є 3 5 Є

4) Convert the RE: 10 + (0 + 11) 0*1


10

1 Є 0
1 2 3
4

0+11

0
Є
Є 2 4

8
1 Є Є
1 Є 1

3 5 6 7

0*1

Є Є Є 1
1 2 0 3 4 5 6
Є

10 + (0 + 11)0*1
Introduction 1.120

1 Є 0
2 3 4 5
Є
Є

1
1 Є 0
9

8 9 
Є
1
Є Є 0 Є
1 1 1 1
6 7 11 5 6 7 8
4
Є Є
1 Є 1 Є
1 Є
0 1 1 1
1 2 3

5) Convert the RE: 00(0+1)* to  – NFA


00

0 Є 0
1 2 3
4

(0+1)*

0
3 4 Є
Є 0 0
Є Є
1 2 7 8
0 Є Є 0 0
1
5 6
0
5 Є

00(0+1)*
1.121 Theory of Computation

0
9
8

0 Є 0 Є Є Є Є
1
1 2 3 4 5 6 7 1
Є Є 2 3
1
1 1
0 1
Є

6) Convert the RE:- (0+1)* (00+11) (0+1)* to  – NFA


(0+1)*

Є 0
3 4

Є Є
1 2 7 8
Є Є
1
5 6

00+11:-

0 Є 0
1 3 4 5
2
Є
Є

1
1
0
Є
Є 1 Є 1
6 7 8 9
Introduction 1.122

(0+1)*(00+11)(0+1)*

Є 0 Є 0
0
1 Є
Є
Є 1 Є
Є Є Є
Є
1 Є
1 Є 1

Є
0
Є
Є
Є Є

1
Є Є
Є

1.12 EQUIVALENCE AND MINIMISATION OF AUTOMATA

Two finite automata m1 and m2 are said to be equivalent if they accept the same language.

i.e., L (m1) = L(m2)

Two FA m1 and m2 are not equivalent over ∑ if there exists a string w such that,

(or)
1.123 Theory of Computation

EXAMPLE:
1) Show that the automata given below are equivalent or not.

c c
d

q1 d q4 q5

d q1
d
c d
d c c

q1 c q6 q7
c

M M
1 2

Step 1:
Here the start states are <q1> and <q4>
We shall start with <q1, q4> over ∑ ={c, d}

Step 2:
State <q2, q6> over ∑ ={c, d}
Introduction 1.124

Step 3:
State <q3,q7> over ∑ ={c, d}

Step 4:
State <q2, q5> over ∑ ={c, d}

Thus every state in m3 has been expanded.


The construction of combine DFA is as follows.

d
<q1 , q4> <q2 , q5>

d c
d c

<q2 , q6> <q3 , q7>


c

<q1 , q4> → both are final states


<q2 , q5> → Non final states
<q2 , q6> → Non final states
1.125 Theory of Computation

<q3 , q7> → Non final states


From the state obtained from the above states, m1 and m2 are equivalent.
Example: c, cccc, dd, ddcc, dcdcd, dcddcdcc, …. are accepted by both m1 and m2.
1.13 MINIMIZATION OF DFA
Minimization of DFA is a process of constructing an equivalent DFA with minimum number
of states.
Equivalent states/ k – equivalence
Let qi and qj are k – equivalent states if and only if no string of length ≤ k can distinguish
them.
If there exists a string of length k, which can distinguish q i and qj, the states qi and qj are said
to be k – distinguishable.
Algorithm
Algorithm for minimization divides states of a DFA into blocks such that:
1. States in a block are equivalent.
2. No two states taken from two different blocks are equivalent.
The first step is to partition the states of M into blocks such that all states in a block are o-
equivalent. This is done by placing,
a. Final states into one block
b. Non-final states into another block
c. The next step is to obtain the partition, P1 whose blocks consists of the set of states
which are 1- equivalent [length = 1]
PROBLEMS
1) Minimise the following DFA
Introduction 1.126

0 1 0
q q q q
0 1 2 3
0 1
1
0 1
1 1 0
q q q q
4 5 6 7
1
0
0

Solution
0 - Equivalence partitioning:
The given set of states in the DFA are classified into two,
1) States that are not final states bock 1
2) Final states block 2
P0
block1 = {q0, q1, q3, q4, q5, q6, q7}
block2 = {q2}
1 – Equivalence partitioning:
This divides the existing non final states based on the inputs that the states accept.
Processing input ‘0’:

 Equivalent states since the transition result in same output.


1.127 Theory of Computation

Processing Output –‘1’:-

 Equivalent states

From the above process of input o and 1, {q3, q5}-, {q1, q7} are a set of equivalent states.
1 – equivalence partitioning
P1 = (q3 , q5) , (q1, q7), (q0,q4,q6), (q2)

Block 11 Block 12 Block 13 Block 2

2 – Equivalence partitioning:
Block – 11

Mapped to the same block, Block 2

Mapped to the same block, Block 12

Block – 12

Mapped to the same block, Block 13


Introduction 1.128

Mapped to the same block, Block 2

Block – 13

→ belong to the same block Block 12

→ belong to the same block Block 11

Here q6 doesn’t map with any other states hence it is distinguished from {q0, q4}
2 – Equivalence partitioning
P2 = (q3, q5), (q1, q7) (q0, q4) (q6) (q2)
Since further partitioning cannot be done, the final minimized DFA is given by

0
1

<
0 1
q2>
< q0, q4> < q1, q7>
0
1
0

1
<q6>
< q1, q7
>
1 0

2) Minimise the DFA given below AU MAY 2007


1.129 Theory of Computation

Input a b
States

→ q0 q0 q3
q1 q2 q5
q2 q3 q4
q3 q0 q5
q4 q0 q6
q5 q1 q4
* q6 q1 q3

0- equivalence partitioning
P0 = (q0, q1, q2, q3, q4, q5) (q6)

block 1 block 2

1 – equivalence partitioning

There are no equivalent states. But still, q4 is the distinguishable state from the rest of the
states
P1 (q0, q1, q2, q3, q5) (q4) (q6)

block 11 block 12 block 2


Introduction 1.130

2 – equivalence partitioning:
From the above transitions, there are no equivalent states but there are distinguishable states,
{q2, q5} since

→ block 11

→ block 12

P2 = (q2, q5) (q0, q1, q3) (q4) (q6)

Block 111 Block 112 Block 12 Block 2


3- Equivalence partitioning:

Since no states are equivalent, q0, q1, q3 are distinguishable from each other.

Block 111 B-1121 B1122 B1123 B12 Block 2

4 - Equivalence partitioning:

But again in 4 – equivalence partitioning, (q2, q5) is considered.


1.131 Theory of Computation

(q2, a) = q3 → block 1123

(q5, a) = q1 → block 1122

(q2, b) = q4 → block 12

(q3, b) = q4 → block 12

P4 = (q2) (q5) (q0) (q1) (q3) (q4) (q6)

Thus the given DFA cannot be minimized since no equivalent states are obtained.

3) Construct a min –DFA for

Inputs 
0 1
States ↓

→ q0 q1 q4
q1 q2 q5
* q2 q3 q7
q3 q4 q7
q4 q5 q8
* q5 q6 q1
q6 q7 q1
q7 q8 q2
* q8 q0 q4

o- equivalence Partitioning:-
P0 =(q0, q1, q3,q4,q6,q7) (q2,q5,q8)
Introduction 1.132

Block 1 Block 2
1- equivalence partitioning:-

From the above transitions,


P1 = (q0, q3, q6) (q1, q4, q7) (q2, q5, q8)

block 11 block 12 block 2


2- Equivalence partitioniong:

Block 12 Block 12
1.133 Theory of Computation

Block 2 Block 2

Block 11 Block 11

P2 = (q0,q3,q6) (q1,q4,q7) (q2,q5,q8)


The States cannot be further subdivided.
The minimized DFA is given by

0, 1
{q1, q4, q7}
{q0, q3, q0}

0, 1
0

1
{q2, q5, q8}

1.14 PROVING LANGUAGES NOT TO BE REGULAR


The following theorem, known as “Pumping Lemma for Regular Languages” is used as a
tool to prove that certain languages are not regular. The principle behind this lemma is
“Pigeon Hole principle.”
PIGEON – HOLE PRINCIPLE
If ‘n’ objects are put into ‘m’ containers, where n > m, then at least one container must hold
more than one object.
Theorem: // Pumping Lemma AU NOV/DEC 2013
Introduction 1.134

Let L be a regular language, then there exist a constant n (which depends on L) such that for
every string w in L such that , we can break ‘w’ into 3 strings:

w = xyz
such that
(i) y ≠ 

(ii)

(iii) For all k ≥ 0, the string xykz is also in L.


i.e., we can always find a non – empty string y not too far from the beginning of w that
can be pumped (repeating y any number of times or deleting it keeps the resulting
string in the language, L.
PROOF
Suppose L is regular, then L = L [A] for some DFA, A. Suppose A has n states.
Consider any string, w of length ‘n’or more, say w = a1, a2,… am where m ≥ n and ai is an
input symbol. For i = 0,1,2,….,n define state where is the
transition function of A and q 0 is the start state of A. i.e, P i is the state A after reading the
first I symbols of w.
Assume that, q0 = P0 = (q0, Є). Since we have only n states, it is easy to see that every string
consisting ‘n’ or more symbols must cause at least a state to repeat. (This principle is called as
Pigeon hole principle).
Therefore, we can find two different integers I and j such that 0 ≤ i < j ≤ n with Pi = Pj. By
assuming the loop occurs are Pi, we can break the string w as,
w = xyz such that
(i) x =x a1, a2, ….ai
(ii) y = ai+1, a1+2,….aj
(iii) z = aj+1, aj+2,….am

y = ai+1, a1+2, ... ,aj


x = a1, a2, …, ai z = aj+1, aj+2, …, am

P0 Pi Pn-1

That is, x takes us from P0 to Pi once, y takes us from Pi back to Pi (since Pi is also Pj ) and z
takes us from Pi to Pn-1. Note that x may be empty in the case that i = 0, also z may be empty if
1.135 Theory of Computation

j = n = m. However y cannot be empty since I is strictly less than j. Now consider what
happens if the automaton A receives the input xykz for any k ≥ 0.
Case 1:
If k = 0, then the automaton from the start state q 0 (which is also Po) to Pi on input x. Since Pi
is also Pj it must be that A goes from Pi to the accepting state on input z. Thus accepts xz.
Case 2:
If k > 0 , then A goes from q0 to Pi on input, x circles from Pi to Pi, k – times on input y k and
then goes to the accepting state on input, z Thus for any k ≥ 0, xy kz is also accepted by A that
xykz is in L. Therefore we can say that L is a regular language.
PROBLEMS

1) By using pumping lemma, P.T the language, is not a regular


language.
Solution

Assume that L is a regular language Let n be a constant and such that . By


pumping lemma, w can be splitted into 3 parts such that w = xy with

(i) y ≠  [ i.e, ]

(ii)

(iii) xykz  L

Since y≠ 

x= 0 n-1 // since

y=0 // Since

z = 10n
Thus

(i) y≠ 

(ii)

(iii) When k = 0; xykz = xy0z = xz = 0n-110n Є L.


The number of zeroes should be equal. Here it is a contradiction.
Introduction 1.136

L is not a regular language


2. Show that the language, L = {aibj,ck/ 0 ≤ i < j < k} is not regular.
Assume that L is regular and let n be any integer. Consider the string, w = anbn+1cn+2. Then
> n.

By pumping lemma, w can be splitted as w = xyz such that

(1)

(2)

(3) xykz  L for k ≥ 0

Since

x = an-1 xy = an-1. a1 = an

y=a

z = bn+1 cn+2
At k = 0:-
xy0z = xz
= an-1.bn+1.cn+2 = an-1.bn+1.cn+2
At k = 1:-
xy1z = an-1.a. bn+1.cn+2
= an.bn+1.c n+2
At k = 2:-
xy2z = an-1.a.a. bn+1.cn+2
= an+1.bn+1.cn+2
Comparing the powers of a, b and c, the language L is not regular.
3) Show that L = {ap | p is a prime number} is not regular. AU – DEC 2007, NOV 2011
Assume that L is regular and n be any integer. Let P ≥ n is a prime number and w = ap Є L.
By pumping lemma, w can be written as w = xyz such that
1.137 Theory of Computation

(i)

(ii)

(iii) xykz  L

Let,

Y = am where m ≥ 1

Consider xykz = xyz . yk-1 Let w= ak ; k → first prime


xykz = xyz.yk-1 k+1 → Next prime > P

= P + (k-1) =k+k

= P + (k-1)m = k(1+ ) → not prime

= P + Pm ← k = p+1 P = k -1
= P(1+m)
Both p and (1+m) are greater than 1. The product of P and (1 + m) cannot be prime
xykz L for k = p+1
L is not regular
4) Show that L = {0n 1n | n ≥ 1} is not regular. AU MAY 2004, DEC 2004, DEC 2005

Assume that L is a regular language. Let n be a constant and w = 0n 1n such that . By


pumping lemma, w can be splitted into 3 parts such that w = xyz with

(i) y ≠  (i.e )

(ii)

(iii) xykz  L

Since and y ≠  ,

x= 0n-1
y=0
z = 1n
Introduction 1.138

By pumping lemma, xykz ≥  L for k ≥ 0


When k = 0;
xy0z = xz
0n-1.1n
L [Comparing the power of 0 and 1 with w]
L is not a regular language.

5) show that L = is not a regular

AU MAY 2006, DEC 2006, DEC 2007, DEC 2008


When , i = 1; L = { } = a1

i = 2; L = { } = aaaa = a4

i = 3; L = { } = aa

The no of a’s is always a perfect square. Consider L = where length = n2

By pumping lemma, w =xyz, where and xykz  L

At k = 1 xy1z = xyz = 1

2

At k = 2 3

From 2 and 3,

>

4

Since

When and x  
1.139 Theory of Computation

xy 2 z  n 2  n

 xy 2 z < n 2 + n + n +1 [For inequality removal]

 xy 2 z < (n  1) 2

From 4 and 5,

n 2 < xy 2 z < (n  1) 2

Example: n = 2; n2 = 22 = 4

(n+1) = 2+1  (n+1)2 = 32 = 9


2
There is no perfect square between 4 and 9. Henceforth, xy z is not a perfect square since
there is no perfect square between n and (n+1)
 xyz  L since xykz  L

 L is not regular.


m,n m  n
6) Using Pumping lemma, prove that L = o o 
m  1 and n  1 is not regular.
AU DEC 2006, DEC 2013, MAY 2013
Let us assume that L is regular and L is accepted by a FA with ‘n’ states.

Let w = o m,n o m  n

w  m  n  (m  n)  2(m  n)  n

Let w = xyz such that,

y > 0 and

xy  n

 x  o m 1

y=0
z = 1n om+n
At k = 0; xykz  xyoz = om-1.1n.om+n 1
From (1), the powers of O is not equal with that of L
Introduction 1.140

Hence xyz  L
 L is not regular language.

R
7) Using pumping lemma, P.T:- L = {ww w (0,1)*} is not regular. AU DEC 2006

Let us assume that L is regular and is accepted by a FA with n states.


Let w = anb
wR = ban
L = wwR ={anbban}
Consider w = xyz such that

(i) y > 0

(ii) xy  n

(iii) xy k z  L  k  0

Let w be splitted as,


x = a n-1
y=a
z = b.b.an
At k = 0:-
xykz  xy0z  xz = an-1.b.b.an
Since the powers of a does not match, L is not regular.

8) Using Pumping lemma, P.T:- {w.w | w  (0, 1)*} is not regular.


Let us assume that L is a regular and is accepted by a FA with ‘n’ states.
Let w = anb
 L = {ww} = {anbanb}

Let w =xyz such that

(i) y > 0

(ii) xy  n
1.141 Theory of Computation

(iii) xy k z  L  k  0
 w can be splitted as

x = a n-1
y=a
z =b.an b.
At k = 0:-
xykz  xy0z  xz = a n-1.b.an b
Since the powers of a does not match with w, L is not regular.
1.15 CLOSURE PROPERTIES OF REGULAR LANGUAGES
AU MAY 2012, MAY 2013, NOV 2010, NOV 2011, NOV 2013, NOV 2012
If an operation on regular languages generates a regular language, then we say that the class of
regular languages is closed under the above operation.
Some of the important closure properties of RL are as follows.
1. Union
2. Difference
3. Concatenation
4. Intersection
5. Complementation
6. Transpose / Reversal
7. Kleene star
8. Homomorphism
9. Inverse homomorphism
Closure under Union
Theorem
If L and M are regular languages, then LUM is also regular.
Proof
Let, L = L [R]
Introduction 1.142

M = L[S]
LUM = L[R] U L [S]
= L [R+S]
Example

Let m1 = ( S, ∑, 1 , So, F) and

m2 = (Q, ∑,  2 , q0, G) be two given automata

Now m3 = L [m1] U L [m2]

= (R, ∑, 3 , ro, H),

Where r0 → New start state having two Є – moves from r0 → s0 and r0 → q0 being added,
R = SUQ U{r0}
H = FUG

3  1 U  2 U{(ro , ,s o ), (ro ,, q o )}

Hence, L [m3] = L[m1] U L [m2]


Thus, Regular Language is closed under Union.
Closure under Complementation
Theorem

If L is a regular language over the alphabet, ∑ then L   *  L is also a regular language.


Proof
Let L= L [A] for some DFA, where
A = (Q, ∑,  , q0, F)

Then, L = L [B], where

B = (Q, ∑,  , q0, Q-F)


i.e., B is exactly like A, but the accepting states of A have not become the accepting states of
B and vice-versa.
Then w is in L [B], if and only if,

(q 0 , w) is in {Q  F} , which occur if and only if w is not in L [A].
1.143 Theory of Computation

Example
Find the complement of (0+1)*01

0,1
0 1
q0 q0
q0

Here,
QN = {q0, q1, q2}
∑= {0, 1}
q0 = {q0}
FN = {q2}


N → 0 1
QN

q0 {q0, q1} {q0}

q1  {q2}

*q2  

By subset construction technique,

QD = {, {q0}, {q1},{q2}, {q0, q1}, {q0, q2}, {q1, q2},{q1, q2, q3}}
FD = {{q2}, {q0, q2},{q1, q2},{q1, q2, q3}}

D ∑
0 1
QN

  

 {q0} {q0, q1} {q0}

{q1}  {q2}

* {q2}  

{q0, q1} {q0, q1} {q0, q2}

* {q0, q2} {q0, q1} {q0}

* {q1, q2}  {q2}

* {q0, q1, q2} {q0, q1} {q0, q2}


Introduction 1.144

Reachable states from {q0}/ Minimised D is

0
1
0 1
{q0, q1}
{q0} {q0, q2}
0

Complement of DFA

0
1

{q0 0 1
{q0, q1} {q0, q2}
}
0

Closure under Intersection


Theorem

If L and M are two regular languages, then L  M is also regular language.

Proof

We define A = (QL x QM, ∑,  (q L , q m ), q L xq m , FL xFm )

where,

 ((p, q), a)   L (p, a),  M (q, a)


1.145 Theory of Computation

L[A]  L [A L ]  L[A M ]

By induction on w ,

 ((q L , q M ), w)   M(q M , w))

But A accepts w if and only if  ((q L , q M ), w) is a pair of accepting states

(i.e.,)  (q L , w) must be in FL and

 (q M , w) must be in FM

Putting in another way, “ w is accepted by A if and only if both AL and AM accepts w.


Thus A accepts the intersection of L and M.
Example

Construct A  B where A and B is given by

1
0,11
0
A p
q

0 0,11

1
r s
B

AA = (QA, ∑, δA, qa, FA)


AB = (QB, ∑, δB, qB, FB)

A B  (Q A x Q B , ,  (q A x q B , FA x F B )

Where

 (( p, q), a)  L (p, a) ,  M (q, a))

Here,
QA x QB = {p,q} x {r,s}
={(p, r), (p, s), (q, r), (q, s)}
Introduction 1.146

Z = {0, 1}

qA x qB = {p, r}
FA x FB = {q, s}


δ(qA, qB) 0 1
Q↓

→ {p, r} {q, r} {p, s}

{p, s} {q, s} {p, s}

{q, r} {q, r} {q, s}

* {q, s} {q, s} {q, s}

Finite Automata

{p, r } 1 {p, s }

0
0

{q, r } 1
{q, s }
0, 1
0

Closure under Reversal


Theorem
If L is a regular language, then L R is also regular.
Proof
1.147 Theory of Computation

Assume L i9s defined by regular expression. The proof is a structural induction on the size of
E. We show that there is another regular expression.
ER such that L(ER) = (L(E))R.
That is the language ER is the reversal of the language of E.
Basis

If  = Є /  / a, then

ER = /  / a
 E = ER

Induction
There are 3 cases depending on the form of E.
1) E = E1 + E2 then ER = E1R + E2 R
The justification is that the reversal of the union of two languages is obtained by
computing the reversals of the two languages and taking the union of those languages.
2) E = E1.E2 then ER = E2R. E1R
Example: L (E1) = {01,111}; L (E2) = {00, 10}
Then, L (E1. E2) = {0100, 0110, 11100, 11110}
L (E1 . E)R = {0010, 0110, 00111, 01111} 1
L(E1)R = {10,111}
L (E2)R = {00,01}
L(E2)R. L (E1)R = {0010, 0110, 00111, 01111} 2
From (1) and (2) L (E1E2) R = L(E2)R. L (E1)R

3) E, E1* then ER , ( E1R )*

The justification is that any string w in L (E) can be written as w1, w2,…, wn where each w1 is
in L(E). But,

w R  w Rn w Rn 1 .......w1R

Each w1R is in L (ER), so wR is in ( E1R ) Conversely any string in L ( E1R )* is of the form w1, w2,
…wn, where each w1 is the reversal of a string in L(E1). The reversal of the string,
w Rn  w Rn 1 .......w1R is therefore a string in L ( E1* ) which is L (E).
Introduction 1.148

Thus a string is in L (E) if and only if its reversal is in L (E1R ) *

Example: If L = (0 + 1)0*
Then LR = 0* (0 + 1) [By applying closure under concatenation, and union]
Closure under Difference
Theorem
If L and M are regular languages then L – M is also regular

L  M  L M

Proof

Since M is a regular language, M is also a regular language by closure under


complementation. Since L and M are regular, the L M is also regular by closure under
intersection.
 L – M is a regular Language.

Closure under Concatenation

Let M1  ( s, , 1 , s o , F)

and M 2  ( Q, ,  2 , q o , G) be two given automata.

Theorem

If two languages, M1 and M2 are regular, then L (M1) . L (M2) is also regular.

L(M3) = L (M1). L (M2)

M3 is given by, M3 = (R, ∑, δ3, so, G)

δ3 = δ1 U δ2 U {Є – move from every final state of M1 to start state of M2}

Closure under kleene star

Theorem

Let M1 = (Q, ∑, δ, q0, F) be the given automata. Then M2 can be constructed such that, L(M2)
= L (M1)*.

M2 is constructed as:

(i) A new start state so is added with an  – move is from so to qo.


1.149 Theory of Computation

(ii) A new final state f0 is added with  – move is added from s0 to fo as  id s


member of L(M1)*.

M2 = (qU{s0, f0}, ∑, δ , s0, {f0})

Homomorphism

A string homomorphism is a function on strings that works by substituting a particular string


for each symbol.

Example: Let n(0) = ab

h(1) = 

h(0011) = h(0)h(0)h(1)h(1)

= abab

Theorem

If L is a regular language over an alphabet, ∑ then h is a homomorphism function on


∑then h (L) is also regular.

Proof
To prove: L [h(E)] = hb [L(E)]
Basis

If E =  or , then

H(E) =  or
 L[h(E)] = L (E)

If E is  or , then L(E) contains either no strings or a string with no symbols.


Thus,
H[l (E)] = l(E) = L[h(E)]
If E = a, then
L(E) = {a}
h[(E)] = {{h(a)} = L[h(E)] for E = {a}
Induction
There are 3 cases in induction part → Union, Concatenation and closure.
Introduction 1.150

Let E = F + G
L[h(E)] = L[h(F + G)]
= L[h(F) U h (G)]
= L[h(F)] U L[h(G)] 1
H[L(E)] = h[L(F + G)]
= h [L(f) U L (G)]
= h [L(f)] U h [L(G)] 2
Therefore by induction, from (1) and (2)
L[h(f)] = h[L(f)] and
L[h(G)] = h [L(G)]
Similarly concatenation and closure is also true,
 L[h®] = h[L(R)]  Hence proved

Inverse homorphism

h 1 (L) is the set of strings, w in ∑* such that h(w) is in L.

Theorem
If h is a homomorphism from alphabet, ∑ to alphabet T and L is regular language over T, then
h 1 (L) is also a regular language.

Proof

We construct a DFA, A for L, then a DFA for h 1 (L) by using A and h. This DFA uses the
states of A but translates the input symbol according to h before deciding on the next state. Let
L be L(A) where DFA, A |(Q, ∑,δ, q0, F) define a DFA, B = (Q, ∑, γ, q0, F) where the
transition function γ is constructed by,

 (q, a)  (q, h (a)). It is a easy induction on w to show that
 
 (q, h (w))   (q, w)

Since the accepting states of A and B are same, B accepts w if and only if A accepts h(w) i.e.,
B accepts exactly those strings w that are in h 1 (L)

Example: Suppose h is a homomorphism from the alphabet {0, 1, 2} to the alphabet {a, b}
defined by h(0) = a, h(1) = ab, h(2) = ba.
1.151 Theory of Computation

(i) h (0120) = h (0)h(1)h(2)h(0)


= aabbaa
(ii) h(21120) = h(2)h(1)h(1)h(2)h(0)
= baababbaa
(iii) L[01*2]
H(L) = h(01*2)
= L[h(01*2)]
= L[h(0)h(1*)h(2)]
= L[a(ab)*ba]

(v) h 1 (L)  h-1(ababa) where L = ababa

= h-1(a)h-1(ba)h-1(ba)
= 022.

You might also like