0% found this document useful (0 votes)
0 views

BCS503_MODULE1_MODULE5_NOTES

Theory of computation notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

BCS503_MODULE1_MODULE5_NOTES

Theory of computation notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

Theory of Computation

BCS503
Finite Automata

Chapter1
FINITE AUTOMATA
Finite automata are basic modules of a computer system, which addresses simple real time
problems. Figure 1.1 shows conceptual view of finite automata. It has an input tape, read head and
finite controller. Input tape is divided into finite cells and each cell stores one input symbols. Read
head is used to read the input symbol from the input tape. The finite controller used to record the
next state of finite automat.

Figure 1.1: Conceptual view of finite automata


Before discussing finite automata in detail, it is very much important to know the basic
requirement for the finite automata. They are
i. Sets.
ii. Graphs.
iii. Languages.
iv. Star closure.
v. Plus closure.
Sets (S):
A set is collection of elements, each element has its own identity. A set can be represented
by enclosing its elements in curly braces. for example, the set of small letters a, b, c is shown as
S= {a, b, c}
Set {2, 4, 6,…} denotes the set of all positive even integers. we can use more explicit notation,
in which we write
S={i | i is > 0 and is even}
We can perform following operations on sets, they are
a. union (∪),
b. intersection (∩), and
c. difference (−)
d. complementation defined

as S1 U S2 = {x | x ϵ S1 or x ϵ
S2} S1 Ո S2 = {x | x ϵ S1 and x ϵ

S2} S1 - S2 = {x | x ϵ S1 and x
S2}

The complement of a set S, denoted by Ṡ consists of all elements not in S. To make this
meaningful, we need to know what the universal set U of all possible elements is. If U is
specified, then
Page 1.
2
Finite Automata

Ṡ={x | x ϵ U, x S}
The set with no elements, called the empty set or the null set, is denoted by ɛ. From the definition of
a set, it is obvious that
S U ɛ = S - ɛ =S

SՈɛ=ɛ

ἕ= U
De Morgan's laws: The following useful identities, known as De Morgan's laws.

are needed on several occasions.


Subset and Proper Subset: A set S1 is said to be a subset of S, every element of S1 is also an element of
S. We write this as S1 ⊆ S. If S1 ⊆ S, but S contains an element not in S1, we say that S1 is a proper
subset of S; we write this as S1 ⊂ S.
Disjoint Sets: If S1 and S2 have no common element, that is, S1 ∩ S2 = ɛ then the sets are said to be
disjoint.
Finite and Infinite sets: A set is said to be finite if it contains a finite number of elements; otherwise it
is infinite. The size of a finite set is the number of elements in it; this is denoted by |S|.
Power- Set: A given set has many subsets. The set of all subsets is called the power-set and is
denoted by 2s. Observe that 2s is a set of sets.
If S is the set {a, b, c}, then its powerset is
2s= {ɛ,{a}, {b}, {c}, {a, b},{b, c},{a, c}, {a, b. c}} Here
|S| = 3 and |2s| = 8.
Cartesian product: Ordered sequences of elements from other sets are said to be the Cartesian
product. For the Cartesian product of two sets, which itself is a set of ordered pairs, we write
S= S1 x S2
Let S1 = {2, 4} and S2 = {2, 3, 5, 6}. Then S1 × S2 = {(2, 2), (2, 3), (2, 5), (2, 6), (4, 2), (4, 3), (4, 5), (4,
6)}. Note that the order in which the elements of a pair are written matters. The pair (4, 2) is in S1 ×
S2, but (2, 4) is not.

Graphs:
A graph is a construct consisting of two finite sets, the set V = {υ1, υ2,…, υn} of vertices and the set E =
{e1, e2,…, em} of edges. Each edge is a pair of vertices from V, for instance,

ei=(v, vj).

Languages:

A finite, nonempty set of symbols are called the alphabet and is represented with symbol ∑. From
the individual symbols we construct strings, which are finite sequences of symbols from the
Page 1.
3
Finite Automata

alphabet. For example, if the alphabet ∑ = {0}, then ∑* to denote the set of strings obtained by
concatenating zero or more symbols from ∑.

We can write ∑*= {ɛ, 0, 00, 000 …}


If ∑ = {0, 1}
0 and 1 are input alphabets or symbols, then:
(02=00, 03=000, 12=11, 13=111, where as in mathematics they are numbers 02=0, 12=1)
L=∑*={ ɛ, 0, 1, 00, 01, 10, 11, 000, 001, 010 ........ }

Kleen closure(*closure):
*closure = {∑0U∑1U∑2U∑3.......... }
∑0={ ɛ} ∑1={0, 1} ∑2={00, 01, 10, 11}
∑3={000, 001, 010, 011, 100, 101, 110, 111}
Therefore ∑*={ ɛ , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101,……}
+Closure on ∑ = {0, 1}

∑+= {∑1U∑2U∑3…}
∑*=∑+ + ɛ

Therefore ∑+=∑*- ɛ
Formal Languages and Automata Theory: IT is a mathematical model used to design computer
programs and sequential logic circuits. It is state machines which captures and makes transition to
accept or reject.
Finite automata has input tape, read head and finite controller Input tape: It is divided into finite
cell and each cell is used to store one input symbol. Read head: Read head is used to read input
symbol from input tape. Finite Controller: Finite controller records, the transition to next state.
The default value of finite controller is initial state q0. States are represented with circles; they are
of three types,

Figure 1.2: Different types of states used in finite automata


States are connected by lines called transition. It has two ends, one end is called initiation point and
the other end is called termination point (>).

Initiation Termination
The combination of transitions and states is called a transition diagram.

Figure 1.3: A typical transition diagram

Figure 1.4 shows a transition diagram to map cities and their roads.

Page 1.
4
Finite Automata

Figure 1.4: Finite automata with real time example.


Finite Automata are classified into two types. They
are:
1) Deterministic Finite Automata (DFA)
2) Non Deterministic Finite Automata (NFA)
In Deterministic Finite Automata number of outgoing transitions are well defined from each state
depending upon input symbols. For example, if there is one Input symbol, then you find one
outgoing transition from each state, for two input symbols two outgoing transitions are present and
so on.

Example 1.1: Draw the DFA, the input symbol is ∑= {0}

Figure 1.5: DFA’s for input symbol ∑= {0}.

Example 1.2: Draw the DFA, the input symbol is ∑= {0, 1}

Figure 1.6: DFA’s for input symbol ∑= {0, 1}.


Definition of DFA: we define DFA as,
MDFA = (Q, ∑, δ, Initial state, Final state)

Where, Q is set of states, ∑ =set of input symbols, δ: transition function is


From the table 1.
Q={q0,q1,q2} ∑ ={a, b, c}

δ:
δ (q0, a)=q1 δ (q0,b)=q0 δ
(q0,c)=q2
δ (q1,a)=q1 δ (q1,b)=q2 δ (q1,c)=q0
δ (q2,a)=q2 δ (q2,b)=q1 δ (q2,c)=q2
Note: Initial State is q0 and final state is q2

Page 1.
5
Finite Automata

Table 1.1: Transition table

Q\∑ a b c

q0 q1 q0 q2

q1 q1 q2 q0

*q2 q2 q1 q2

Nondeterministic Finite Automata (NFA):

If outgoing transitions are not dependent on number of input symbols, then such automata are called
as Nondeterministic Finite Automata.
For example: ∑ = {0, 1}

Figure 1.7: Nondeterministic Finite Automata for ∑ = {0, 1}

There is no outgoing transition from initial state, for a symbol ‘1 ‘and similarly there is no outgoing
transition from final state for ‘0’.
Transition Function for string:
Note: 1) δ is the transition function, used for symbols.

2) For the string (Set of symbols), is used


{}=ɛ
{a}=a

(q0, ɛ)= q0 //q0 is reading empty string, string is empty


therefore, transition to same state q0.

(q0, a)= (q0, ɛa)= δ ( (q0, ɛ),a)= δ

(,a) Therefore (q0, a)= δ (q0, a)

Therefore for single symbol string = δ

(q0, wa)

Where ‘w’ is the multi-symbol string and ‘a’ is a symbol, hence we separate the transition function for
strings and symbols as given

below: δ ( (q0, w), a)

Page 1.
6
Finite Automata

Example 1.3: Write a transition table for a DFA shown in figure


1.8. DFA over alphabet ∑ = {a, b}

Figure 1.8: Transition diagram o0f a DFA.


Table 1.2: Transition table for the figure 1.8

MDFA =(Q, ∑, δ , IS,


FS) Q ={ q0, q1}
∑ ={a ,b}
δ (q0, a) =q1 S δ q0,b)
=q0 δ (q1, a) =q1 δ (q1,
b) =q0 IS =q0 FS={q0}
Example 1.4: Construct transition table for the diagram shown in figure 1.9, over the alphabet ∑={0,

1, 2}
Figure 1.9: Transition diagram
Table 1.3: Transition table for the figure 1.9

We can define above DFA as: MDFA=(A, ∑, δ, IS,

{FS}) δ:
δ (A0, 0)=A1 δ (A0, 1)=A2 δ(A0,
2)=A0 δ (A1, 0)=A2 δ (A1, 1)=A0
Page 1.
7
Finite Automata

δ(A1, 2)=A1
δ (A2, 0)=A2 δ (A2, 1)=A1 δ(A2, 2)=A0

A ={A0,A1,A2}; ∑ ={0,1,2}; IS=A0; FS=A2


String Acceptance:
The first symbol of string begins with initial state. Later, traverses zero or more than zero
intermediate state(s) for the intermediate symbol(s). Finally last symbol of the string ends with
final state of automata. This is called string accepted or otherwise string is not accepted.

Example 1.5: Find out whether the given string is accepted by the DFA. Assume the string as
abab. From the given string ∑ = {a,b} . Note that always string is traversed by left side to right
side,

Figure 1.10: Transition diagram for example

1.5. (q0, a)= δ (q0, a)= q 2 1

(q0, ab)= δ ( (q0, a) b ) from 1 (q0, a)= q2

= δ (q2, b) =q3 2
(q0, aba)= δ( (q0, ab), a) from equation 2 (q0, ab)= q3
= δ(q3, a)=q1
(q0, abab)= δ( (q0, aba), b)
= δ( (q1, b)= q0
Given string is accepted by a

DFA.
Page 1.
8
Finite Automata

Example 1.6: Find out the language accepted by the DFA.

Figure 1.12: Transition diagram of Example 1.6.

δ (q0, a)=q1; (q0, aa)= δ ( (q0, a),a)= δ (q1, a)=

q1 L={a, aa, ba, baa, aba, …..}

In general we can write:

L= {w |w is a string ending with symbol a}

Example 1.7: Find out the language accepted by the DFA.

Figure 1.13: Transition diagram of Example 1.7

Initial state is also a final state, hence it accept empty string

ɛ. (q0, ɛ)=q0;

(q0, aa)= δ( (q0, a)a)= δ(q2, a)=q0;

(q0, bb)= δ( (q0, b)b)= δ(q1, b)=q0;


Therefore language L={ ɛ, aa, bb, aabb,
abab…}
In general we can write L={w |w is a string consist of even number of a’s and even number of b’s}
Design of DFA :
Example 1.8: Design a DFA which accept all the strings ends with symbol a over the alphabet ∑={a, b}.
L={a, aa, ba, aba, bba…}

i. Draw the NFA for the smallest string a of the


language. The NFA for the string a is

Page 1.
9
Finite Automata

Figure 1.14 : NFA for the string a


Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for symbol ‘a’
another for ‘b’. From initial state only one outgoing transition on symbol ‘a’, one more outgoing
transition is required that is on ‘b’. If the condition in the given problem ends with, the outgoing
transition on the other symbol b, definitely loop to a initial state.

Figure 1.14: second outgoing transition from state q0

Figure 1.15 : q0 is termination for symbol b and q1 is termination for symbol a


Termination state for symbol ‘a’ is q1 and for ‘b’ it is q0. Outgoing transition from q1
on symbol ‘a’ is loop, and for ‘b’ it is to q0 .

Figyre 1.16 :DFA which accept all the strings ends


with a. We can define above DFA as MDFA =(Q, ∑, δ , IS,
{FS})
Q ={ q0, q1}
∑ ={a , b}
δ (q0, a) =q1 δ (q0,b)
=q0 δ (q1, a) =q1 δ (q1,
b) =q0 IS =q0 FS={q1}
Example 1.8: Design a DFA which accept all the strings ends with substring 01 over the alphabet
∑={0, 1}.

L={01, 001, 101, 0001,1001…}.

i. Draw the NFA for the smallest string 01 of the


language. The NFA for the string 01 is

Figure 1.17: NFA for the string 01.

ii. Convert all states of NFA to DFA, that is from each state two outgoing transitions, one
for symbol ‘0’ another for ‘1’. From initial state only one outgoing transition on symbol
Page 1.
10
Finite Automata

‘0’, one
more outgoing transition is required that is on ‘1’. If the condition in the given problem
is, ends with, the outgoing transition on the other symbol 1, definitely loop to a initial
state.

Figure 1.18 : conversion of NFA state A0 to DFA

Figure 1.19 : A0 is termination for symbol 1 and A1 is termination for symbol 0

Termination state for symbol ‘0’ is A1 and for ‘1’ it is A0. Outgoing transition from A1
on symbol ‘0’ is loop. From A2 on symbol ‘0’ to A1 and on symboll ‘1’ to A0.

Figyre 1.20 :DFA which accept all the strings ends with
01. We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2}; ∑={0, 1}
δ:
δ (A0, 0)=A1 δ (A0,
1)=A0 δ (A1, 0)=A1 δ
(A1, 1)=A2 δ (A2, 0)=A1 δ
(A2, 1)=A0 IS=A0; FS=A2
Example 1.9: Design a DFA which accept all the strings ends with substring 012 over the alphabet
∑={0, 1, 2}.

L={012, 0012, 1012, 00012,10012…}.


i. Draw the NFA for the smallest string 012 of the
language. The NFA for the string 012 is

Figure 1.21: NFA for the string 012.


ii. Convert all states of NFA to DFA, that is from each state three outgoing transitions, one
for symbol ‘0’ second for ‘1’ third from ‘2’. From initial state only one outgoing transition
on symbol ‘0’, two more outgoing transitions are required that is on ‘1’ and ‘2’. If the
Page 1.
11
Finite Automata

condition in the given problem ends with, the outgoing transition on the other symbols
‘1’and ‘2’, definitely loop to a initial state.

Figure 1.22: conversion of NFA state A0 to DFA state.

Figure 1.23: A0 is termination for symbol 1, 2 and A1 is termination for symbol 0

Termination state for symbol ‘0’ is A1 and for ‘1’ and ‘2’ is A0. Outgoing transition from
A1 on symbol ‘0’ is loop and for’2’ is A0. From A2 on symbol ‘0’ to A1 and on symbol ‘1’ to
A0. From A3 on symbol ‘0’ to A1 and on symbols ‘1’ and ‘2’ to A0.

Figure 1.24 :DFA which accept all the strings ends with
012. We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2, A3}; ∑={0, 1, 2}

δ:
δ (A0, 0)=A1 δ (A0, 1)=A0 δ(A0, 2)=A0
δ (A1, 0)=A1 δ (A1, 1)=A2 δ(A1, 2)=A0
δ (A2, 0)=A1 δ (A2, 1)=A0 δ(A2, 2)=A3
δ (A3, 0)=A1 δ (A3, 1)=A0 δ(A3, 2)=A0
IS=A0; FS=A3
Example 1.10: Design a DFA which accept all the strings begins with symbol ‘a’ over the alphabet

∑={a, b}.

L={a, aa, ab, abb, aba, aaa…}


i. Draw the NFA for the smallest string a of the
language. The NFA for the string a is

Figure 1.25: NFA for the string a.

Page 1.
12
Finite Automata

Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘a’ another for ‘b’. From initial state only one outgoing transition on symbol ‘a’,
one more outgoing transition is required that is on ‘b’. If the condition in the given
problem is, begin with, the outgoing transition on the other symbol ‘b’, is to new state
called dead state. Dead state: In finite automata the string travers from initial state to
final state, in some situation we make finite automata to die called dead state. Dead state
is a non-final state, from which all outgoing transitions are loop to the same state.

Figure 1.26 : DFA which accept all the string begin with a.
ii. Condition is begin, outgoing transitions from final state is loop.

We can define above DFA as MDFA =(Q, ∑, δ , IS,


{FS}) Q ={ q0, q1, q2}
∑ ={a , b}
δ (q0, a) =q1 δ (q0,b)
=q2 δ (q1, a) =q1 δ (q1,
b) =q1 δ (q2, a) =q2 δ
(q2, b) =q2 IS =q0
FS={q1}
Example 1.11: Design a DFA which accept all the strings begins with substring 01 over the alphabet

∑={0, 1}.
L={01, 010, 011, 0100, 0101…}.

i. Draw the NFA for the smallest string 01 of the


language. The NFA for the string 01 is

Figure 1.27: NFA for the string 01.

ii. Convert all states of NFA to DFA, that is from each state two outgoing transitions, one
for symbol ‘0’ another for ‘1’. From initial and intermediate states only one outgoing
transition, one more outgoing transition is required. If the condition in the given
problem is, begin with, the outgoing transition from both the states to new state called
dead state.

Page 1.
13
Finite Automata

Figure 1.28 : DFA which accept all the string begin with 01.

iii. Condition is begin, outgoing transitions from final state A2 on symbol ‘0’ and ‘1’ is
loop. We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2 A3}; ∑={0, 1}

δ:
δ (A0, 0)=A1 δ (A0,
1)=A0 δ (A1, 0)=A1 δ
(A1, 1)=A2 δ (A2, 0)=A1
δ (A2, 1)=A0 δ (A3, 0)=A3
δ (A3, 1)=A3 IS=A0; FS=A2

Example 1.12: Design a DFA which accept all the strings begins with 01 or ends with 01 or both over
the alphabet ∑={0, 1}.
L={01, 010, 011, 0100, 001, 101, 0001,1001, 0101, 01101…}
We have already designed both the DFAs, joining of these DFAs, is the solution for the given problem.

Figure 1.29: DFA which accept all the string begin with 01.

Figure 1.30: DFA which accept all the string ends with 01.

Page 1.
14
Finite Automata

Figure 1.31: DFA which accept all the string begin with 01, end with 01 begin and end with 01.
Example 1.13: Design a DFA which accept all the binary strings divisible
by 2. L={ ɛ, 10, 100, 110, …}
To design DFA we need to make the following assumptions.

From the above assumption, we can draw the following DFA.

Figure 1.32: DFA which accepts all the strings divisible by

2. We can define above DFA as MDFA =(Q, ∑, δ , IS, {FS})


Q ={ q0, q1}
∑ ={0, 1}
δ (q0, 0) =q0 δ (q0,1)
=q1 δ (q1, 0) =q0 δ (q1,
1) =q1 IS =q0 FS={q0}
Example:
Example 1.14: Design a DFA which accept all the binary strings divisible
by 5. L={ ɛ, 101, 1010, 1111, …}

Figure 1.33: DFA which accept all the strings divisible by 5.

Page 1.
15
Finite Automata

We can define, designed DFA as MDFA=(A, ∑, δ, IS,


{FS}) A={ q0, q1, q2 q3, q4} ∑={0, 1}
δ:
δ (q0, 0)=q0 δ (q0, 1)=q1 ; δ (q1, 0)=q2 δ (q1, 1)=q3
δ (q2, 0)=q4 δ (q2, 1)=q0 ; δ (q3, 0)=q1 δ (q3, 1)=q2
δ (q4, 0)=q3 δ (q4, 1)=q4 ;

IS=q0; FS=q0

Example 1.15: Design a DFA which accept string over x, y every block of length 3 contains at least
one x. To design a DFA we need to make following assumptions,
1. If there is no ‘x’ in the string, such a string should not be accepted.

Figure 1.34: NFA which is not accepting three y’s string.

2. One ‘x’ in the string, accepted by finite automata.

Figure 1.35: NFA which is accepting three symbol string in which one symbol is x.

3. The position of A1 and A5 is same as A0 and A4. In between A0 and A4 the symbol is
‘x’, inbetwwen A1 and A5 is also x and so on.

Figure 1.36: DFA which accept string over x, y if every block of length 3 contains at least one x.
We can define designed DFA as MDFA=(A, ∑, δ, IS,
{FS}) A= { A0, A1, A2, A4, A4, A5, A6} ∑={x, y}
δ:
δ (A0, x)= A4 δ (A0, y)= A1 ; δ (A1, δ (A1,
x)=A5 y)=A2
δ (A2, x)=A6 δ (A2, y)=A3; δ (A3, x)=A3 δ (A3, y)=A3
δ (A4, x)=A5 δ (A3, y)=A5; δ (A5, x)=A6 δ (A5, y)=A6 ;

Page 1.
16
Finite Automata

δ (A6, x)=A4 δ (A6,

y)=A1 IS=A0; FS={ A6}

Example 1.16: Design a DFA which accept even number of r and even number of s over the symbol
∑={r,
s}.

i. Draw separate DFA, one accept even number of r’s and another one accept even number
of s’s.

Figure 1.37 : DFA’s accept even symbols string over r, s.

ii. Join two DFA, we get four new states AB, AC, BC, BD. Designed DFA accept even number
of r and even number of s, out of four states AB satisfied this condition, hence this state
is a final state.

Figure 1.38: DFA which accept even number of r and s.


We can define designed DFA as MDFA=(State, ∑, δ, IS,
{FS}) State={ AC, AD, BC, BD} ∑={r, s}
δ:
δ (AC, r)= BC δ (AC, s)= AD ; δ (BC, r)=AC δ (BC, s)=BD
δ (AD, r)=BD δ (AD, s)=BD; δ (BD, r)=AD δ (BD,

s)=BC IS=AC; FS={ AC}


Example 1.17: Design a DFA which accept all the strings described by the language L={N0(w)≥ 1
and
N1(w)=2}

i. Exchange I symbol of first string with the last symbol of the first string, the string
obtained is the second string of the language.
ii. Draw NFA for two smallest strings, for both NFA initial and final states are same.

Page 1.
17
Finite Automata

Figure 1.39: Two DFAs for the string 011 and 110 with same initial and final state.

Figure 1.40: DFA which accept all the strings described by the language L={N0(w)≥ 1 and
N1(w)=2}. We can define designed DFA as MDFA=(A, ∑, δ, IS, {FS})
A={ A0, A1, A2 A3, A4, A5, A6} ∑={0, 1}
δ:
δ (A0, 0)=A1 δ (A0, 1)=A4 ; δ (A1, 0)=A0 δ (A1, 1)=A2
δ (A2, 0)=A2 δ (A2, 1)=A3 ; δ (A4, 0)=A2 δ (A4, 1)=A5
δ (A5, 0)=A3 δ (A5, 1)=A6 ; δ (A6, 0)=A6 δ (A6, 1)=A6

IS=A0;
FS={A3}

Nondeterministic Finite Automata (NFA)

In DFA the outgoing transitions are defined in advance, where as in NFA the outgoing transitions
are not defined in advance. In DFA, the string is either accepted or not accepted, where as in NFA
both are possible. The finite automata shown in the figure 1.41 is a NFA. There is no outgoing
transition for the symbol ‘a’ from the state q1.

Figure 1.41: Nondeterministic Finite Automata


We can define above NFA as MDFA =(Q, ∑, δ , IS,
{FS}) Q ={ q0, q1,}
∑ ={a , b}
δ:

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


=q0 δ (q1, b) =q0
δ (q2, a) =q2 δ (q2, b) =q2
IS =q0 FS={q1}

Page 1.
18
Finite Automata

The NFA shown in figure 1.42 is, accepting as well as not accepting the string hod.

Figure 1.42:Non-deterministic finite automata

Example 1.18: Design NFA which accept all strings, if second symbol from right side is 1 over
the alphabet ∑={0, 1}.

L={ 10, 110, 010, 0110…}

i. First step draw the final state.

Figure 1.43: Final state

ii. Draw the intermediate state and transition for the symbols ‘0’ and ‘1’.

Figure 1.44: Intermediate and final states

iii. Draw the initial state and transition for the symbol ‘1’.

Figure 1.45: Non-deterministic finite automata accepting two strings 10, 11.

iv. Designed NFA has to accept all the strings, if second symbol from right side is symbol
‘1’, to do this, mark loop to initial state on symbols ‘0’ and ‘1’.

Figure 1.46: NFA which accepts all strings, if second symbol from right side is 1 over the alphabet
∑={0, 1}.

v. Name the states and stop.

Figure 1.47: NFA which accept all strings, if second symbol from right side is 1 over the alphabet ∑={0,
1}.
Page 1.
19
Finite Automata

Definition of NFA: NFA can be defined as

MDFA =(Q, ∑, δ , IS,


{FS}) Q ={ q0, q1, q2}
∑ ={0, 1}
δ:
δ (q0, 0) =q0 δ (q0,1) ={q0,
q1} δ (q1, 0) =q2
δ (q1, 1) =q2
IS =q0 FS={q2}

Equivalence of NFA and DFA:

We have already seen both NFA and DFA, both are same in the definition but they differ in
transition function. If number of states in NFA has two states q0 and q1. Here, q0 is initial state and q1
is final state. The equivalent states in DFA’s are *q0], [q1] and [q0, q1]. Where q0 is initial state and
(q1), (q0, q1) are the final states. The pair (q0, q1) is final state because; one of its states is final state.
They are represented as shown in figure 1.48

Figure 1.48: Equivalence states of NFA and DFA.

Example 1.19: Convert the NFA shown in figure 1.49 into its equivalent DFA.

Figure 1.49: Non-deterministic finite automata of Example 1.19.

The conversion begins with the initial state of the NFA which is also an initial state of DFA.
Conversion generates number of new states, for every new state we are finding the outgoing
transitions for different symbols.

Table 1.4: Different tables for the conversion of NFA to DFA.

Page 1.
20
Finite Automata

No further new states; mark the final state of DFA. Any pair of state which consists of final state of
the NFA, the particular pair is a final state in DFA.

Figure 1.50: Equivalence DFA of figure 1.49

Application of Finite automata:

Finite automat is used to search a text. There are two methods used to search text, they are:

i. Nondeterministic Finite Automata(NFA)


ii. Deterministic Finite Automata(DFA)

To search a text “shine” and “hire” the NFA shown in figure 1.51 is

used The input alphabets are ∑={s, h, i, n, e, r }

Figure 1.51: NFA used to search strings shine and hire

To search a text “shine” and “hire” the DFA shown in figure 1.52 is used

Page 1.
21
Finite Automata

Figure 1.52: DFA used to search strings ending with shine and hire

Example 1.20: Design a finite automata, that reads string made up of letters HONDA, and
recognize those string that contain the word HOD as a substring.

i. Find out the alphabet from the string HONDA. The input symbols are ∑={H, O, N, D, A}
ii. Draw the NFA for the substring HOD.

Figure 1.53: NFA used to search string HOD

iii. Convert NFA state of figure 1.53 into DFA states.

Figure 1.54: DFA accept all the strings ends with HOD over the symbols {H, O, N, D, A}

NFA with ɛ-transition:

Till now whatever automata we studied were characterized by a transition on the symbols. But there
are some finite automata having transition for empty string also, such NFAs are called NFA- ɛ
transition.

ɛ-closure (q0): states which are closed / related to state q0 on empty transition(ɛ) is called ɛ-closure
(q0).

In DFA and NFA (q0, ɛ)=q0, where as in ɛ-NFA


i. (q, ɛ)= ɛ-closure( (q, ɛ))= ɛ-closure(q).
ii. (q, x)= ɛ-closure(δ( (q, ɛ), x)= ɛ-closure(δ(ɛ-closure(q), x).
iii. (q, wx)= ɛ-closure(δ( (q, w), x).

Example 1.21: Find out ɛ-closure of all the states of ɛ-NFA shown in figure 1.55.

Page 1.
22
Finite Automata

Figure 1.55: NFA with ɛ-transition of Example 1.21.

Figure 1.56: ɛ-closure of all the states of figure 1.55


Example 1.22: Convert the ɛ-NFA shown in figure 1.57 into NFA

Figure 1.57: ɛ-NFA of Example 1.22.

First find out the ɛ-closure of all the states.

Note: state ɛ-closure consist of final state of ɛ-NFA, the particular state is a final state in NFA.

(q0, 0)= ɛ-closure(δ( (q0, ɛ), 0).

= ɛ-closure(δ({q0q1}, 0).

= ɛ-closure(δ(q0, 0) U δ(q1, 0)).

=ɛ-closure(q0 U q2).

=ɛ-closure(q0) U ɛ-closure(q2).

={q0q1} U {q0q1q2}

={q0q1q2}

(q0, 1)= ɛ-closure(δ( (q0, ɛ), 1).

= ɛ-closure(δ({q0q1}, 1).

= ɛ-closure(δ(q0, 1) U δ(q1, 1)).

Page 1.
23
Finite Automata

=ɛ-closure(q0 U φ).

=ɛ-closure(q0) U ɛ-closure(φ).

={q0q1}

(q1, 0)= ɛ-closure(δ( (q1, ɛ), 0).

= ɛ-closure(δ(q1, 0)).

= ɛ-closure(q2).

={q0q1q2}

(q1, 1)= ɛ-closure(δ( (q1, ɛ), 1).

= ɛ-closure(δ(q1, 1)).

= ɛ-closure(φ).

(q2, 0)= ɛ-closure(δ( (q2, ɛ), 0).

= ɛ-closure(δ({q0q1q2}, 0).

= ɛ-closure(δ(q0, 0) U δ(q1, 0)U δ(q2, 0)).

=ɛ-closure(q0 U q2 U φ).

=ɛ-closure(q0) U ɛ-closure(q2) U ɛ-closure(φ).

={q0q1} U {q0q1q2} U (φ)

={q0q1q2}

(q2, 1)= ɛ-closure(δ( (q2, ɛ), 1).

= ɛ-closure(δ({q0q1q2}, 1).

= ɛ-closure(δ(q0, 1) U δ(q1, 1) U δ(q2, 1)).

=ɛ-closure(q0 U φ U φ).

=ɛ-closure(q0) U ɛ-closure(φ) U ɛ-closure(φ)

=(q0 q1) U (φ) U (φ)

= {q0q1}

Page 1.
24
Finite Automata

Table 1.5: Equivalence table of ɛ-NFA and NFA.

Figure 1.58: NFA without ɛ-

transition. Conversion of ɛ-NFA to

DFA:

It is same as conversion of NFA to DFA, begins with initial state of ɛ-NFA.

Example 1.23: Convert the ɛ-NFA shown in figure1.59 into DFA.

Figure 1.59: ɛ-NFA of Example 1.23.

First find out the ɛ-closure of all the states

Table 1.6: Equivalence table of ɛ-NFA and NFA.

(q0, 0)= ɛ-closure(δ( (q0, ɛ), 0).

= ɛ-closure(δ({q0q1}, 0).
Page 1.
25
Finite Automata

= ɛ-closure(δ(q0, 0) U δ(q1, 0)).

=ɛ-closure(φ U q1).

=ɛ-closure(φ) U ɛ-closure(q1).

= φ U q1

=q1

(q0, 1)= ɛ-closure(δ( (q0, ɛ), 1).

= ɛ-closure(δ({q0q1}, 1).

= ɛ-closure(δ(q0, 1)U δ(q1, 1)).

=ɛ-closure(q0U φ).

=ɛ-closure(q0) U ɛ-closure(φ).

={q0q1}U φ

=[q0q1]

(q0, 2)= ɛ-closure(δ( (q0, ɛ), 2).

= ɛ-closure(δ({q0q1}, 2).

= ɛ-closure(δ(q0, 2)U δ(q1, 2)).

=ɛ-closure(φ U q2).

=ɛ-closure(q2).

=[q1q2 ]

(q1, 0)= ɛ-closure(δ( (q1, ɛ), 0).

= ɛ-closure(δ(q1, 0).

= ɛ-closure(q1).

= q1

(q1, 1)= ɛ-closure(δ( (q1, ɛ), 1).

= ɛ-closure(δ(q1, 1).

= ɛ-closure(φ).

Page 1.
26
Finite Automata

= φ

(q1, 2)= ɛ-closure(δ( (q1, ɛ), 2).

= ɛ-closure(δ(q1, 2)

= ɛ-closure(q2)

= [q1 q2]

([q0q1], 0)= ɛ-closure(δ( ([q0q1], ɛ), 0)

= ɛ-closure(δ( (q0, ɛ)U (q1, ɛ)), 0).

= ɛ-closure(δ((q0, q1) U q1), 0)).

= ɛ-closure(δ((q0, q1), 0)).

= ɛ-closure(δ(q0, 0) U δ(q1, 0)).

= ɛ-closure(φ U q1)

= ɛ-closure(q1)

= q1

([q0q1], 1)= ɛ-closure(δ( ([q0q1], ɛ), 1)

= ɛ-closure(δ( (q0, ɛ)U (q1, ɛ)), 1).

= ɛ-closure(δ((q0, q1) U q1), 1)).

= ɛ-closure(δ((q0, q1), 1)).

= ɛ-closure(δ(q0, 1) U δ(q1, 1)).

= ɛ-closure(q0 U φ)

= ɛ-closure(q0)

= [q0, q1]

([q0q1], 2)= ɛ-closure(δ( ([q0q1], ɛ), 2)


= ɛ-closure(δ( (q0, ɛ)U (q1, ɛ)), 2).

= ɛ-closure(δ((q0, q1) U q1), 2)).

= ɛ-closure(δ((q0, q1), 2)).

= ɛ-closure(δ(q0, 2) U δ(q1, 2)).

Page 1.
27
Finite Automata

= ɛ-closure(φ U q2 )

= ɛ-closure(q2)

= [q1 q2]

([q1q2], 0)= ɛ-closure(δ( ([q1q2], ɛ), 0)


= ɛ-closure(δ( (q1, ɛ)U (q2, ɛ), 0)).

= ɛ-closure(δ(q1U (q1 q2)), 0).

= ɛ-closure(δ(q1, q2), 0 )).

= ɛ-closure(δ(q1, 0 ) U δ (q2, 0 ))

= ɛ-closure(q1 U φ).
= ɛ-closure(q1)

= q1

([q1q2], 1)= ɛ-closure(δ( ([q1q2], ɛ), 1)

= ɛ-closure(δ( (q1, ɛ)U (q2, ɛ), 1)).

= ɛ-closure(δ(q1U (q1 q2)), 1).

= ɛ-closure(δ(q1, q2), 1 )).

= ɛ-closure(δ(q1, 1 )U δ (q2, 1 ))

= ɛ-closure(φ U φ).
= ɛ-closure(φ)

([q1q2], 2)= ɛ-closure(δ( ([q1q2], ɛ), 2)


= ɛ-closure(δ( (q1, ɛ)U (q2, ɛ), 2)).

= ɛ-closure(δ(q1U (q1 q2)), 2).

= ɛ-closure(δ(q1, q2), 2)).

= ɛ-closure(δ(q1, 2 )U δ (q2, 2 ))

= ɛ-closure(q2 U φ).
= ɛ-closure(q2)

Page 1.
28
Finite Automata

= [q1 q2]

Table 1.7: Equivalence table of ɛ-NFA and DFA.

( φ, (0,1,2))= φ

Mark the final states, any pair which has a final state of ɛ -NFA the particular pair is afinal state in

DFA. Table 1.7: Equivalence table of ɛ-NFA and DFA .

Figure 1.60: DFA of figure 1.59.

Page 1.
29
REGULAR EXPRESSION

Chapter 2

REGULAR EXPRESSIONS
Language represented in the form of expression (symbols separated by operator) is called
regular expression. δ 1U2

∑= {a, b, 0, 1}

Language L= ∑*= {a, b, 0, 1}* ={ Ɛ, a, b, 0, 1, aa, bb, 00, 11…}

Regular expression R= { Ɛ + a + 0 + 1 + aa + bb + 00 + 11…}

Before studying regular expression in detail, we will discuss some fundamental rules of the
regular expression.

i. Φ+1=1 (φ is like, number 0).


ii. Ɛ + 1= Ɛ+1 (Ɛ is like number 1)
iii. φƐ=φ
iv. Ɛ+φ=Ɛ
v. 1+1=1
vi. 0+0=0
vii. 0+1=0+1
viii. 0+01=0(Ɛ+1)
ix. 0Ɛ=0
x. 0φ=0
xi. Φ*={Ɛ+ φ+ φφ…}={Ɛ+φ}=Ɛ
xii. 0++Ɛ=0*
xiii. 0*+Ɛ=0*
xiv. (1+Ɛ)+=1*
xv. (1+φ)+=1+
xvi. 00*=0+
xvii. Ɛ+11*=Ɛ+1+=1*
xviii. (Ɛ+11)(Ɛ+11)*=(Ɛ+11)+=(11)*
xix. (00)*(1+01)=(00)*(Ɛ+0)1= (Ɛ+00+0000.. )(Ɛ+0)1=0*1
xx. Write a regular expression set of strings made up of 0’s and 1’s ending
with 00 RE=(0+1)*00.
xxi. Write a regular expression for all the set of string made up of 0’s and 1’s which begin
with 0 and end with 1
RE=0(1+0)*1
xxii. Strings begins with 0 or 1 is represented as (0+1)(0+1)*
xxiii. All strings begins with 0 or 1 and not having two consecutive
0’s RE=(0+1)(1+10)
xxiv. Write regular expression which consist of two consecutive
0’s RE=(0+1)*00(0+1)*
xxv. All the strings of 0’s and 1’s whose last two symbols are
same RE=(0+1)*(00+11)

Page 2.
30
REGULAR EXPRESSION

xxvi. Sets of all strings which starts with either 00 or 11 or ends with 00 or 11
RE=(00+11) (0+1)* +(0+1)*(00+11).
xxvii. Find the regular expression of the language L={anbm :n≥0,
m≥0} L={Ɛ+a+aa..}{Ɛ+b+bb…}
RE=a*b*
xxviii. Find the regular expression of the language L={anb2m+2 : n≥0,
m≥0} RE=(aa)*(bb)*bb.
xxix. Find the regular expression of the language L={a2nbm : n≥4,
m≤3} RE=(aaaa)*(Ɛ+b+bb+bbb)
xxx. Find the regular expression of the language L={anbm/n+m is
even} RE=(aa)*(bb)*+a(aa)*b(bb)*

Conversion from Regular expression to finite automata:

Three basic regular expressions are used in conversion (0+1), 01 and

0*. The finite automata which accept either 0 or 1 is shown in figure

2.1.

Figure 2.1: Finite automata

But in regular expression each symbol is having its own finite automata.

Definition for the finite automat which accept the symbol ‘1’ is

M1= (Q1,∑1, δ, IS1, FS1)

Q1={C, D}; ∑1=1; δ(C, 1) = D; IS=C; FS=D

Definition for the finite automat which accept the symbol ‘0’ or ‘1’

is M= (Q,∑, δ, IS, FS)

Q={Q0 U Q1 U E U F} ={ A, B, C, D, E. F);

∑= {0, 1}

δ(A, 0)= B; δ (C, 1)= D; δ(E, Ɛ)={A, C}; δ(D, Ɛ)=F: δ(D, Ɛ)=F

IS=E; FS=F

For the symbol ‘0’ the finite automata is shown in figure 2.2

Page 2.
31
REGULAR EXPRESSION

Figure 2.2: Finite automata for regular expression 0.


Definition for the finite automat which accept the symbol ‘0’ is

M0= (Q0,∑0, δ, IS0, FS0)

Q0={A, B}; ∑0=0; δ(A, 0)= B; IS=A; FS=B

For the symbol ‘1’ is shown in figure 2.3

Figure 2.3: Finite automata for regular expression 1.

Definition for the finite automat which accept the symbol ‘1’ is

M1= (Q1, ∑1, δ, IS1, FS1)

Q1={C, D}; ∑1=1; δ(C, 1)= D; IS=C; FS=D

We are joining these two finite automata with disturbing the regular expression 0+1 as shown in
figure
2.4. To join these two finite automata we need more extra states, one for the initial state and second
is for the final state, states A and B no more initial states and B and D are no more final states. All
these states will now become intermediate states as shown in figure 2.4.

Figure 2.4: Finite automata for regular expression 0+1.

Definition for the finite automat which accept the symbol ‘0’ or ‘1’

is M= (Q,∑, δ, IS, FS)

Q={Q0 U Q1 U E U F} ={ A, B, C, D, E. F);

∑={0, 1}

δ(A, 0)= B; δ (C, 1)= D; δ(E, Ɛ)={A, C}; δ(D, Ɛ)=F: δ(D, Ɛ)=F

IS=E; FS=F

For the regular expression 01 the finite automata is shown in figure 2.6.

Page 2.
32
REGULAR EXPRESSION

Figure 2.5: Finite automata for regular expression 0 and 1.

Rewrite the expression 01 as 0Ɛ1.

We can join the two finite automata shown in figure2.5 and figure 2.6 without disturbing the
regular expression 01 is shown in figure 2.6.

Figure 2.6: Finite automata for regular expression 01.

Definition for the finite automat which accept the string 01

is M= (Q,∑, δ, IS, FS)

Q={Q0 U Q1} ={ A, B, C, D);

∑={0, 1}

δ(A, 0)= B; δ (C, 1)= D; δ(B, Ɛ)= C

IS=A; FS=D

Like that we can design the finite automata for 0*.

0*= {Ɛ, 0, 00, 000…}

The regular expression for symbol ‘0’ is shown in figure 2.7

Figure 2.7: Finite automata for regular expression 0.

The designed finite automata accept all the strings of 0* ie., {Ɛ, 0, 00, 000…}

Figure 2.8: Finite automata for regular expression 0*.

Definition for the finite automat which accept the string 0*

is

Page 2.
33
REGULAR EXPRESSION

M= (Q,∑, δ, IS, FS)

Q={Q0 U E U F} ={ A, B, E, F);

∑=0

δ(A, 0)= B; δ (E, Ɛ)= {A, F}; δ(B, Ɛ)= {F, A}

IS=E; FS=F

Example 2.1: Design a finite automat for the regular expression 0*1

i. Draw the finite automata for the symbol ‘0’

Figure 2.9: Finite automata for regular expression 0.

ii. Convert the finite automata of symbol ‘0’ to 0*

Figure 2.10: Finite automata for regular expression 0*.

iii. Draw the finite automata for the symbol ‘1’

Figure 2.11: Finite automata for regular expression 1.

Join finite automata of 0* and 1, which will be the solution for the regular expression 0*1

Figure 2.12: Finite automata for regular expression 0*1.

Example 2.2: Design a finite automat for the regular expression 0(0+1)*1
Page 2.
34
REGULAR EXPRESSION

i. Draw the finite automata for the symbol ‘0’ and ‘1’

Figure 2.13: Finite automata for regular expression 0.

Figure 2.13: Finite automata for regular expression 1.

ii. Construct the finite automata for the expression 0 + 1

Figure 2.14: Finite automata for regular expression 0+1.

iii. Construct the finite automata for the symbol (0 + 1)*

Figure 2.15: Finite automata for regular expression (0+1)*.

iv. Join the finite automata of ‘0’, (0+1)* and ‘1’

Figure 2.16: Finite automata for regular expression

0(0+1)*1. Conversion from Finite Automata to Regular

Expression: They are of two methods of conversions,

Page 2.
35
REGULAR EXPRESSION

they are:

i. Recursive Method.
ii. State Elimination Method.

i. Recursive Method :
In this method it uses recursive method, to construct new regular
expression. For example the regular expression of DFA shown in figure

2.17 is

Figure 2.17: A typical Finite automata.

In order to obtain the value of regular expression , we use all the (transition) possible
regular expression of the DFA. The possible regular expression of the figure 2.17 is shown in the
table2.1.

Table 2.1: Recursive table

Equations to obtain the regular expression of all the transitions are as follows:

If state 2 and 3 are final states then the regular expression is written as:

Example 2.3: Find the regular expression of DFA shown in figure 2.17 by using recursive method.

Page 2.
36
REGULAR EXPRESSION

Example 2.4: Find the regular expression of DFA shown in figure 2.18 by using recursive method.

Page 2.
37
REGULAR EXPRESSION

State Elimination Method:

In state elimination method, we obtain regular expression, by eliminating all the intermediate
states. After eliminating the intermediate states, it is easy to find the regular expression for the
remaining states (initial and final).

Figure2.19: Finite automata

The regular expression of the finite automata shown in figure2.20 is:

Figure2.20: Finite automata

RE=01

Figure2.21: Finite automata

Page 2.
38
REGULAR EXPRESSION

The regular expression of the finite automata shown in figure 2.2 is:

Figure2.22: Finite

automata RE=0a*1

From the above examples we come to know that eliminating state has one predecessor state A 0 and
one successor state A2. In complex finite automata the eliminating state may have more number of
predecessors and successors. One Such example is shown in the figure 2.23.

Figure 2.23: Eliminating state E has n predecessor and n successor.

Before eliminating any state from the finite automata, we need to find out the path passing through
the eliminating state. The paths passing through the eliminating state are P1ESn, P1ES1, PnES1 and
PnESn. After eliminating state E, the automata is shown in the figure 2.24.

Figure 2.24: Finite automata after eliminating state E.

After eliminating all predecessors and successors, leaving initial state and final state, the remaining
machine looks shown in the figure 2.25.

Page 2.
39
REGULAR EXPRESSION

Figure 2.25: Finite automata after eliminating all predecessors and successors.

The regular expression is, language accepted by the initial state of finite automata and Su*.

The language accepted by the initial state is {R*+Su*t+R*Su*t + su*tR*…}, this is like {x*+y*+xy + yx
…}

We can simplify it as (x+y)* similarly, we can simplify the language for the initial state as (R+Su*t)*.
Therefore, regular expression of finite automata is (R+Su*t)*Su*. Note that in some cases the same
state is initial as well as final state.

Figure 2.26: Same state is initial as well as final state.

The regular expression is R*.

To eliminate state, three rules are used, they are:

Figure 2.27: One path passing through eliminating state A1

Figure 2.28: Two paths are passing through eliminating state A1

Page 2.
40
REGULAR EXPRESSION

Figure 2.29: Four paths are passing through eliminating state A1

Example 2.5: Construct regular expression for the finite automat shown in figure 2.30.

Figure 2.30: Finite Automata

No intermediate in the given finite automata, hence we can’t eliminate any of the

state. R=b; S=a; u=a; t=b;

Therefore RE =(R+Su*t)*Su*

= (b+aa*b)*aa*

=b(Ɛ+aa*)*aa*

=b(aa*)*aa*

Example 2.6: Construct regular expression for the finite automat shown in figure 2.31 by using state
elimination method.

Figure 2.31: Finite Automata.

We can eliminate one intermediate state A1, the paths passing through the eliminating state are
A0A1A0, A0A1A2, A2A1A0 and A2A1A2.
Page 2.
41
REGULAR EXPRESSION

Figure 2.32: Final finite

Automata RE=(R+Su*t)*Su*

= ((2+02*1)+(1+02*0)(0+12*0)*(2+02*0))*((1+02*0)(0+12*0)*.

Application of Regular expression:

Pumping lemma:

It is used to prove language as non-regular for

example L=(00, 000, 0000…}

The automat is shown in figure 2.33 which accept 00.

Figure 2.33: Finite Automata

The automat is shown in figure 2.34 which accept 000.

Figure 2.34: Finite Automata pumped at intermediate state one

time. The automat is shown in figure 2.35 accept 0000.

Figure 2.35: Finite Automata pumped at intermediate state one time.

If more 0s, there will be more number of pumping. In such a case it is very difficult to count the
number of pumping. To count the number of pump easily we draw circles around the intermediate
state so that we can easily count the number of pumping to prove the language as non-regular.
Page 2.
42
REGULAR EXPRESSION

Figure 2.35: Finite Automata pumped at intermediate state finite

time. We can write uv iw Є L for i={1, 2, 3...}.

To prove the language as non-regular, smallest string of language is divided into uvw by considering
two conditions.

i. V Ɛ.
ii. |UV|≤n where n is the smallest string of the language. To prove the language as a non-
regular, throughout the proof the value of n is constant.

Example 2.7: Prove that the language L={ :i≥1} is not regular.

uviw ЄL for i={1, 2…}

0(00)i000000 ЄL

I=1

000000000

ЄL I=2

00000000000 L

When i=2 the string obtained is not belongs to language, hence proved language is not regular.

Example 2.8: Prove that the language L={anbn+1 :n≥2} is not regular.

i=1

aaabbbb Є L

I=2

Aaabaabbbb L

When i=2 the string obtained is not belongs to language, hence proved the language is non-regular.

Page 2.
43
REGULAR EXPRESSION

Closure Properties of Regular Expression:

Till now we have seen many regular expressions and their applications. These regular expressions
are bounded/ related by operators called closure properties of regular expression. The different
operators used to relate regular expressions are:

i. Boolean.
ii. Reversal.
iii. String Homomorphism and Inverse Homomorphism.
i. Boolean Operator:
They are of different types
a. Union b. Intersection c. Difference d. Compliment.
a. Union Operation.
To perform union operation it uses following steps.
• This operation is applied on two machines
defined as M1=(Q1, ∑1, δ1, IS1, FS1)
M2=(Q2, ∑2, δ2, IS2, FS2)
• Find the language L1 and L2 of the two machines.
• Perform union operation on the two languages L1 and L2 to obtain language L3
• Combine two machines to perform union operation.
• Apply language L3 on combined machines to obtain machine for
union operation.

Same steps are used for the other Boolean operation.

M1UM2=(Q1UQ2, ∑1U∑2, δ1Uδ2, ?, ?)


For example consider the machine 1 is shown in figure 2.36

Figure 2.36: Finite Automata

Machine 2 is shown in figure 2.37

Figure 2.37: Finite Automata

The union operation on two languages is

In order to obtain the finite automata for the union operation, we need to join two finite automata.
The transition table for union operation is shown in table…

Page 2.
44
REGULAR EXPRESSION

Table 2.1: Transition table for Boolean operation

Equivalent diagram is shown in the figure 2.38

Figure 2.38: Finite Automata after combining figure 2.36 and 2.37.

According to union operation it has to accept 0, 00

Figure 2.39: Finite Automata to accept 0, 00.

it has to accepts 1, 01, 11, 011

Figure 2.40: Finite Automata accepts 1, 01, 11,

011. It also accepts 10, 010…

Figure 2.41: Finite Automata accepts 10, 010...

Page 2.
45
REGULAR EXPRESSION

The final automata for the union operation is shown in figure 2.42

Figure 2.42: Union of two finite automata of figure 2.36 and

2.37. For intersection M1 2={10, 100, 010, 1010…}

Figure 2.43: Intersection of two finite automata of figure 2.36 and

2.37. For differentiation M1-2 ={1, 11, 01, 011, 101}

Figure 2.44: Difference of two finite automata of figure 2.36 and 2.37.

Compliment:

To compliment the regular expression it uses the following steps:

i. Obtain the Ɛ-NFA/NFA for the regular expression.


ii. Convert the Ɛ-NFA to DFA.
iii. Compliment DFA.
iv. Convert DFA to regular expression.

Example 2.9: Find the compliment of regular expression 0.

i. Obtain the Ɛ-NFA/NFA for the regular expression.

Figure 2.45: finite automata for regular expression 0.

ii. Convert the Ɛ-NFA/NFA to DFA.

δ(A, 0)=B; δ(B, 0)=φ; δ(φ,0)=φ


Page 2.
46
REGULAR EXPRESSION

Figure 2.46 : Equivalent DFA for the figure 2.45.

iii. Compliment DFA. Reverse all transitions and convert all final to non final and vice-versa.

Figure 2.47: Complimented DFA of figure 2.46.

State B and φ are not reachable from the initial State. Hence the two states are removed from the
finite automata.

Figure 2.48. Complimented DFA for the regular expression 0.

The regular expression of finite automata shown in figure

2.48 is

RE=Ɛ

Reversal of regular expression:

i. Reverse all transitions.


ii. Convert initial state to final and final state to intermediate state.
iii. Draw epsilon-transition between new initial state to all previous final states,
mark new state as an initial state.

Figure 2.49: Non-deterministic finite automata.

Figure 2.50: Reversed NFA of the figure 2.49

String Homomorphism:

String homomorphism is a function on the language, it replaces string by symbol

Page 2.
47
REGULAR EXPRESSION

Figure 2.51: Homomorphism.

Inverse Homomorphism:

It is an inverse string homomorphism

Figure 2.52: Inverse string homomorphism

Example 2.10: Consider the homomorphism, h(0)=abb; h(1)= a; h(011)=abbaa

If the homomorphism from an alphabet {0, 1, 2} to {a, b} is defined by h(0)=ab; h(1)=b; &
h(2)=aa, then:

i. What is h(2201).
ii. If L is language 1*02* what is h(L).
iii. If L is language(ab+baa)*bab then what is h-1(L)
i. h(2201)=aaaaabb
ii. h(L)=h(1*02*)=b*ab(aa)*
iii. (ab+baa)*bab=(0+12)*10

Equivalence and minimization:

In Equivalence, two different DFA’s are given, we need to find out the two DFA’s are similar or
not. By filling table and Preshapat tree we can decide the two DFAs are similar | not similar.

Preshapat Tree: To find pair of nodes similar | not similar Preshapat tree is used. It consists of
root node, intermediate nodes and leaves nodes. The root node of the tree is pair of initial states
of two DFAs. Next we construct branches of tree depending on number of input symbols. If
leaves node do not have a cross in the difference table and same pairs are repeating, we stop
constructing tree and decide the root pair is similar or else dissimilar, any of leaves node has a
cross in the difference table.

Figure 2.53: Deterministic finite automata.

Page 2.
48
REGULAR EXPRESSION

Figure 2.54: Difference table with Preshapat tree.


Leaves node 14 has cross in the difference table, so two DFA’s are not

equal. For example

Figure 2.55: Deterministic finite automata.

Note that root of the tree is pair of initial states. Leaves nodes of the tree do not have cross in the
difference table and nodes are repeating, hence the two DFA’s are similar.

Figure 2.56: Difference table with Preshapat tree.

Example 2.11: Find out the two DFAs are similar or not.

Figure 2.57: Deterministic finite automata.

Page 2.
49
REGULAR EXPRESSION

Figure 2.58: Transition tree with table.

The leaves node AG has X in the table; hence two DFAs are dissimilar.

In case of minimization, the two states are minimized to one state if they are similar. For example
state X and Y are equal, they are replaced by one state as shown in figure 2.59

Figure 2.59: Similar states are replced into single state.

To decide the states are similar | not similar we use Shanprepat tree.

Shanprepat Tree: To find equivalence between pair of states Shanprepat tree is used. It consists of
root node, intermediate nodes and leaves nodes. The root node of the tree is pair of states used to
find the similar | not similar states. Next we construct branches of tree depending on number of
input symbols. If leaves node do not have a cross in the difference table and same pairs are
repeating, we stop constructing tree and decide the root pair is similar or else decide two states are
dissimilar, any of leaves node has a cross in the difference table.

Example 2.12: Using table filling method, minimize the DFA shown in figure 2.60 and draw the
transition diagram of the resulting DFA.

Figure 2.60: Deterministic finite automata.

Figure 2.61: Differnce table with Shanprepat Tree

Figure 2.62: Minimized DFA of the figure 2.60

Page 2.
50
REGULAR EXPRESSION

Example 2.13: Using table filling method, minimize the DFA shown in figure 2.63 and draw the
transition diagram of the resulting DFA.

Figure 2.63: Deterministic finite automata.

From the given DFA we draw the dissimilar table as shown in figure. As compared to final state C all
states are different (non-final states), hence X is marked.

Figure 2.64: Differnce table with Shanprepat Tree.

The leaves node decides the root node. Any leaves node has X in the table, the root node is marked
as X or else pair node repeats. Stop when the pair nodes start repeating, and decide the root node
pair is similar.

Figure 2.64: Differnce table with Shanprepat Tree.

Page 2.
51
REGULAR EXPRESSION

Figure 2.65: Differnce table with Shanprepat Tree.

Figure 2.66: Differnce table with Shanprepat Tree.

Figure 2.66: Differnce table with Shanprepat Tree.

From the table, we come to know that A=E, B=H and D=F. the resulting DFA is shown in figure..

Figure 2.67: Minimized DFA of the figure 2.63

Page 2.
52
REGULAR EXPRESSION

Example 2.14: Using table filling method, minimize the DFA shown in table and draw the
transition diagram of the resulting DFA.

The table shows the dissimilarity in the states of the given problem.

Figure 2.68: Differnce table with Shanprepat Tree.

Page 2.
53
REGULAR EXPRESSION

Figure 2.69: Differnce table with minimized DFA.

Page 2.
54
CONTEXT FREE GRAMMAR

Chapter 3
CONTEXT FREE GRAMMAR
To define a language, English grammar is used such a concept is called as Context Free Language
(CFL) or Context Free Grammar (CFG). For example:

// it is a
symbol. L={0}*={Ɛ, 0, 00, 000, …}

L is represented in the form of grammar

as It means S has two values S=Ɛ or S=

0S

In general grammar is defined as G=(V, T, P, S)

Where, V is a set of variables. (First letters)

T is a set of terminals. (Second letters)

P is Productions

S is starting variable of the grammar.

In order to construct grammar it uses four different types of productions:

i. roduction for finite set of strings, 0*={ Ɛ+0+00…} is

and 0+ ={0+00+000…} the production is

ii. Production which separate the symbols (anbn where, n={0, 1, 2,,}) is

Production which mix the symbols ((ab)n where, n is {0, 1, 2,,}) is .

iii. Production for (0+1)* is .

Example 3.1: Construct the grammar for the language L={anbn

n≥0} L={Ɛ, ab. aabb, ….}

G = (V, T, P, S)

V=S, T= {a, b}

Page 3.
55
CONTEXT FREE GRAMMAR

P is production
S is starting symbol = S

Example 3.2: Construct the grammar for the language L={anbm

|n<m} L= {Ɛ, b. bb, …abb, aabbb ….}

G=(V, T, P, S)

V={S, B} T= {a, b}

P is

production

S=S

Example 3.3: Construct the grammar for palindrome over the ∑={a,

b} L={Ɛ, a, b. aba, abba, bab, baab ….}

G=(V, T, P, S)

V=S, T={a, b}

P is

production

S=S

Example 3.4: Construct the grammar for the language L={x |na(x)=nb(x)}

L={Ɛ, ab. ba, aabb, abab….}

G= (V, T, P, S)

V=S, T= {a, b}

P is

production

S=S

Page 3.
56
CONTEXT FREE GRAMMAR

Example 3.5: Construct the grammar for the language L={x |na(x)
nb(x)} L={a, aab. aba, baa, ….b, bba, bab, abb…}

G= (V, T, P, S)

V={A, B, S} T={a, b}

P is

production

S=S

Example 3.6: Construct the grammar for the language L= {0i1j2k |i=j or

j=k} Describe the language according to four rules mentioned above

For i=j the productions are

For j=k the productions are

To obtain the language L= {0i1j2k |i=j or j=k} club the above productions

G= (V, T, P, S)

V={S, B, A, C, D} T= {0, 1, 2}

P is

production

Page 3.
57
CONTEXT FREE GRAMMAR

S=S

Example 3.7: Construct the grammar for the language L= {xiyjzk |i+2j=k}

Describe the language according to four rules mentioned above

For i=k, j=0 the production is

For i=0, j=k the production is

The production for the language L= {xiyjzk |i+2j=k} is

G= (V, T, P, S)

V= {B, A} T={x, y, z}

P is

production

S=A

Example 3.8: Construct the grammar for the language L= {w|wЄ(0+1)*} with at least one
occurance of 110

L= {110, 1100, 0110, 1110,1101, …

G=(V, T, P, S)

V= {B, A, S} T={0, 1}

P is

production

S=S
Page 3.
58
CONTEXT FREE GRAMMAR

Derivation Tree/parse Tree:

It is a tree, consisting of root node, intermediate node and leaf node. They are of two types:

i. Right Most Derivation Tree (RMD)


ii. Left Most Derivation Tree (LMD)
Right Most Derivation Tree (RMD): In RMD right most variable simplified followed by other
variables.

Left Most Derivation Tree (LMD): In LMD left most variable simplified followed by other variables.

Example 3.9: Construct LMD and RMD for the string xxxyyy using production

Figure 3.1: LMD and RMD for the string xxxyyy

Identifier:

Identifier is letters followed by zero or more than zero letters or digits. We can write identifier in
the form of expression over ∑={a, b, 0, 1} as follows:

I= (a + b) (a+b+0+1)*

Identifier itself is an expression, represented in the form of production as shown below

Expression can be

According to mathematical equation of identifier, we can write the following productions for the
identifier as

Example 3.10: Design grammar for valid expression over operator + and *. The argument of the
expressions is valid identifier over symbols a, b, 0, 1. Derive LMD and RMD for the string
w=(a11+b0)*(b00+001).

Page 3.
59
CONTEXT FREE GRAMMAR

Figure 3.2: LMD for the string w= (a11+b0)*(b00+001).

Figure 3.3: RMD for the string w= (a11+b0)*(b00+001) .

Page 3.
60
CONTEXT FREE GRAMMAR

Ambiguity:

Two different trees for a LMD or RMD called ambiguity. For example, the production:

for the string a+a+a, two LMD and RMD are shown in figure 3.4 and 3.5 respectively.

Figure 3.4: Two different LMD for the production over the string a+a+a

Figure 3.5: Two different RMD for the production

Example 3.11: Show that the given grammar is ambiguous by using LMD and RMD for the
production over a string (()()()).

Page 3.
61
CONTEXT FREE GRAMMAR

Figure 3.6: Two different LMD for the production over a string (()()()).

Figure 3.7: Two different RMD for the production over a string (()()()).

For both RMD and LMD, the tree obtained for the same production has two different trees
called Ambiguity.

Resolve Ambiguity:

There are two reasons for the ambiguity

i. Recursive use of variables.


ii. Similar operands used in the expression.

Page 3.
62
CONTEXT FREE GRAMMAR

To resolve ambiguity, two variables are used

i. Factor: Factor can be identifier or parenthesis expression written as: .


ii. Term: Term is a factor+ given as

Example 3.12: Resolve the ambiguity in the given production

Example 3.13: Resolve the ambiguity in the given production

Page 3.
63
PUSHDOWN AUTOMATA

Chapter 5
PUSHDOWN AUTOMATA (PDA)
To process input string PDA uses stack along with input, such an automata is called Push Down
Automata (PDA). PDA is defined with seven tuples, (Q, ∑, δ, Z0, ┌, IS, FS)

Q is number of states in PDA

∑ is input alphabet

δ is transition function defined as


Z0 is initial symbol of stack

┌ is stack
symbols IS is

initial state FS is

final state

The PDA works on equal symbol, if the input string is 100001.

Figure 5.1: Different position of stack for the input string is 100001.

There are two types of PDA

i. Deterministic Push Down Automata (DPDA)


ii. Non-deterministic Push Down Automata (NPDA)

Deterministic Push Down Automata (DPDA):

In Deterministic Push Down Automata (DPDA), we are designing PDA. The design of PDA begins
with Instantaneous Description (IDs), each IDs consist of state, input string to be processed and
initial symbol of the stack (z0).

Example 5.1: Design DPDA for the string 000111.

The Instantaneous Descriptions (IDs) for the given problem are as follows:

Page 5.1
PUSHDOWN AUTOMATA

By making use of the above IDs we can obtain the transition functions, which are required for the
construction of PDA.

For first transition function, ID1 is used for input transition and ID2 is used as output.

δ(q0, 0, z0)=q0, 0z0

Next ID2 is the input of transition and ID3 is used for output transition function.

δ(q0, 0, 0)=q0, 00

ID3 and ID4 are same as ID2 and

ID3 ID4 and ID5

δ(q0, 1, 0)=q0, Ɛ

ID7 and ID8

δ(q0, Ɛ, z0)=q1,

z0

Figure 5.2: DPDA for the string 000111.

Example 5.2: Design DPDA for the language L={anb2n | n≥0}.

The Instantaneous Descriptions (IDs) for the given problem are as follows

By making use of the above IDs we can obtain the transition functions, which are required
to construct the PDA.

For first transition function, ID1 is used for input transition and ID2 is used as output.

Page 5.2
PUSHDOWN AUTOMATA

δ(q0, a, z0)=q0, aaz0

Next ID2 is the input of transition and ID3 is used for output transition function.

δ(q0, a, a)=q0, aaa

ID3 and ID4

δ(q0, b, a)=q0, Ɛ

ID7 and ID8

δ(q0, Ɛ, z0)=q1,

z0

Figure 5.3 DPDA for the language L={anb2n | n≥0}.

Example 5.3: Design DPDA for the language L={x |

na(x)=Nb(x)}. L={Ɛ, ab, ba, abab, baba, aabb, bbaa …}

The Instantaneous Descriptions (IDs) for the given problem are as follows

By making use of the above IDs we can obtain the transition functions, which are required for the
construction of a PDA.

For first transition function, ID1 is used for input transition and ID2 is used as output.

δ(q0, a, z0)=q0,

az0 Possible

transition δ(q0, b,

z0)=q0, bz0

Next ID2 is the input of transition and ID3 is used for output transition function.

δ(q0, a, a)=q0, aa

Possible transition

Page 5.3
PUSHDOWN AUTOMATA

δ(q0, b, b)=q0, bb

ID3 and ID4

δ(q0, b, a)=q0,

δ(q0, a, b)=q0, Ɛ

ID5 and ID6

δ(q0, Ɛ, z0)=q1,

z0

Figure 5.4: DPDA for the language L={x | na(x)=Nb(x)}.

Example 5.4: Design DPDA for the language L={anbncn| n≥0}.

The Instantaneous Descriptions (IDs) for the given problem are as follows

By making use of the above IDs we can obtain the transition functions, which are required
to construct the PDA.

For first transition function, ID1 is used for input transition and ID2 is used as output.

δ(q0, a, z0)=q0, az0

Next ID2 is the input of transition and ID3 is used for output transition function.

δ(q0, a, a)=q0, aa

ID3 and ID4

δ(q0, b, a)=q0, Ɛ

δ(q0, c, z0)=q0, cz0

δ(q0, c, c)=q0, cc
Page 5.4
PUSHDOWN AUTOMATA

δ(q0, Ɛ, c)=q0, Ɛ

ID8 and ID9


δ(q0, Ɛ, z0)=q1, z0

Figure 5.5: DPDA for the language L={anbncn| n≥0}.

i. Non-deterministic Push Down Automata:

Example 5.5: Design NPDA for the language L={wwR| w={a,

b}*}. L={Ɛ, aa, bb, aaaa, bbbb, abba…}

In NPDA, it treats all the symbols into

i. Symbol of first half continues in the same state and push the symbol to top of the stack.
ii. Symbol of second half, it just changes the state and continues further.

The Instantaneous Descriptions (IDs) for the given problem are as follows

δ(q0, a, z0)=q0, az0

δ(q0, a, a)=q0, aa

δ(q0, a, a)=q1, a

δ(q1, a, a)=q1, Ɛ

δ(q1, Ɛ, z0)=q2, z0

Page 5.5
PUSHDOWN AUTOMATA

Figure 5.6: NPDA for the language L={wwR| w={a, b}*}.


Equivalence of CFG and PDA:

Each CFG has PDA and each PDA has CFG.

i. Converting PDA to CFG


ii. Converting CFG to PDA
i. Converting PDA to CFG
In this method we convert transition functions into variables. Each variable consist of
state, stack symbol and state, all are represented in square bracket [Q, Stack Symbol, Q].

Example 5.6: Convert following transition function of PDA to productions.

δ(q0, a, z0)=q0, XZ0; δ(q0, a, z0)=q0, X;

This conversion method is a blind, we do not have any specific rules

CFG begins with starting symbol. Therefore starting symbol in the form of transition function of PDA
is derived as:

The production for the above transition function can be written as

The production for the above transition function can be written as

ii. Converting CFG to PDA

In this case productions of CFG’s are given; we need to find out equivalent transition functions
of PDA.

Example 5.7: Convert following productions of CFG into transition function of PDA.

Before converting CFG to PDA, see that all productions are in the form of Greibach Normal form.
In Greibach Normal form there should not be undesired production and all the right hand side
production are only terminal or terminal followed by any number of variables.

Page 5.6
PUSHDOWN AUTOMATA

Closure Properties of CFLs:

CFLs are closed under operator; there are different types of operators

i. Union
ii. Concatenation
iii. Star Closure
iv. Intersection of two CFLs
v. Intersection of CFL and regular language
vi. Compliment of CFLs
vii. Reversal.
viii. Substitution.
ix. Inverse Homomorphism,
i. Union:
CFL1=G1=(V1, T1, P1, S1) CFL2=( V2, T2, P2,
S2) CFL3=G3 =(V1UV2, T1UT2, P1UP2,
S1|S2)
ii. Concatenation:
CFL3=G3 =(V1V2, T1T2, P1P2, S1S2)
iii. Star Closure:
CFL1=G1=(V1, T1, P1,
S1) S1=TS1|Ɛ;
iv. Intersection of two CFLs:
CFL1=L1={anbnci :n≥0, i≥0}
CFL2=L2={aibncn :n≥0, i≥0} is not a
CFL

Proof:

L1={Ɛ, c, ab, abc, aabb, cc,

aabbcc…} L2={Ɛ, a, bc, abc, aa,

bbcc, aabbcc…} L3= L1ᴒL2={Ɛ,

abc, aabbcc…}

Page 5.7
PUSHDOWN AUTOMATA

={anbncn :n≥0}
The above language is neither belongs to L1 nor L2 therefore intersection of two CFLs are not CFL.

v. Intersection of CFL and regular


language: CFL =(Q1, ∑1, δ1, ┌1, IS1,
FS1)
Regular language M=(Q2, ∑2, δ2, IS2, FS2)
CFLᴒM=((Q1, Q2), (∑1, ∑2), (δ1, δ2), ┌1, (IS1, IS2), (FS1, FS2))
Intersection consist of seven tuples, it is a CFL.

Figure 5.7: Intersection of CFL and regular language.


vi. Compliment of
CFLs CFL1, CFL2
According to De’morgan’s theorem

vii. Reversal:
In this case the right hand side of production is reversed.

viii. Substitution:
h(0)= aba; h(1)= ba
h(010)=ababaaba
S(0)= {anbn:n≥0}; S(1)={aa, bb}
S(01)={anbnaa, anbnbb}
ix. Inverse Homomorphism:

Figure 5.8: Homomorphism and inverse homomorphism

Figure 5.9: Substitution and inverse substitution.

Figure 5.10: PDA for Substitution method.

Page 5.8
TURING MACHINE

Chapter 6
TURING MACHINE
Turing machine was invented by Alan Turing in 1936. It is a mathematical model of computer.
Turing machines prove fundamental limitations on the power of mechanical computation. While
they can express arbitrary computations, their minimalistic design makes them unsuitable for
computation in practice: real- world computers are based on different designs that, unlike Turing
machines, use random-access memory.

Turing completeness is the ability for a system of instructions to simulate a Turing machine. A
programming language that is Turing complete is theoretically capable of expressing all tasks
accomplishable by computers; nearly all programming languages are Turing complete if the
limitations of finite memory are ignored.
The pictorial representation of Turing machine is shown in the figure 6.1. The machine consists of a
finite control, which can be in any of a finite set of states. It has an input tape divided into finite
cells; each can hold one symbol. Initially an input string over alphabet is stored in the tape. Default
value of tape is blank symbol called B, it is a tape symbol it is not an input symbol. There is a tape
head always pointing at the leftmost cell of the tape. A move of the Turing machine is a function of
the state of the finite control and the tape symbol scanned. In one move Turing machine will:
i. Change state. The next state optionally may be the same as the current state.
ii. Write a tape symbol in the cell scanned. This tape symbol replaces whatever symbol
was in that cell.
Turing machine can be defined with 5-tuples
MT= (Q, ∑, δ, B, ┌, IS, FS)
Q= Number of states used in the Turing machine.
∑= {a, b}
┌ = Tape symbol {a, b, B}
B = Blank symbol.
δ:
Q x ∑=Q, ┌, D where, D is direction

IS= Initial State of

TM. FS= Final state

of TM.

For example if the input string is aabb, it is stored in the input tape shown in figure 6.1.

Figure 6.1: Turing Machine.


Page 6.1
TURING MACHINE

Turing machine uses IDs to process string; the IDs consist of state and input string. The IDs for
the string aabb is shown below.

Page 6.2
TURING MACHINE

δ(q0, a)=q1, X, R;
δ(q1, a)=q1, a, R;
δ(q1, b)=q2, Y, L;
δ(q2, a)=q2, a, L;
δ(q2, X)=q0, X, R;
δ(q2, Y)=q2, Y, L;
δ(q0, Y)=q0, Y, R;
δ(q0, B)=q3, B, R;

Figure 6.2: Turing machine for the string


aabb. MT=(Q, ∑, δ, B, ┌, IS, FS)
Q={q0, q1, q2, q3}
∑={a, b, c}
┌ = Tape symbol {a, b, c, B, X, Y} B
= Blank symbol.
δ: is defined above
IS=q0
FS=q3

Example 6.1: Design a Turing machine for the language L={anbncn : n≥1}
The processing of string aabbcc is shown below.

δ(q0, a)=q1, X, R;
δ(q1, a)=q1, a, R;

Page 6.3
TURING MACHINE

δ(q1, b)=q2, Y, R;
δ(q2, b)=q2, b, R;
δ(q2, c)=q3, Z, L;
δ(q3, Z)=q3, Z, L;
δ(q3, b)=q3, b, L;
δ(q3, Y)=q3, Y, L;
δ(q3, a)=q3, a, L;
δ(q3, X)=q0, X, R;
δ(q1, Y)=q1, Y, R;
δ(q2, Z)=q2, Z, R;
δ(q0, Y)=q0, Y, R;
δ(q0, Z)=q0, Z, R;
δ(q0, B)=q4, B, R;
δ(q0, B)=q3, B, R;

Figure 6.3: Turing machine for the language L={anbncn : n≥1}


MT=(Q, ∑, δ, B, ┌, IS, FS)
Q={q0, q1, q2, q3, q4}
∑={a, b, c}
┌ = Tape symbol {a, b, c, B, X, Y, Z} B
= Blank symbol.
δ: is defined above
IS=q0
FS=q4
Example 6.2: Design a Turing machine for the language L={wwR : w=(0+1)*}
The IDs for the string is shown below.

δ(q0, 0)| δ(q0, 1)=q1, X, R;


δ(q1, 0)| δ(q1, 1)=q2, Y ,
L; δ(q1, 1)=q1, 1, R;

Page 6.4
TURING MACHINE

δ(q1, 0)=q1, 0, R;
δ(q2, X)=q0, X, R;
δ(q2, 0)=q2, 0, L;
δ(q2, 1)=q2, 1, L;
δ(q0, Y)=q0, Y, R;
δ(q0, B)=q3, B, R;

Figure 6.4: Turing machine for the language L={wwR : w=(0+1)*}.


Example 6.3: Design a Turing machine for the language L= {ww : w=(0+1)*}.
The IDs for the string is shown below.

δ(q0, 0)| δ(q0, 1)=q1, X, R;


δ(q1, 0)| δ(q1, 1)=q2, Y , L;
δ(q1, 1)=q1, 1, R;
δ(q1, 0)=q1, 0, R;
δ(q2, X)=q0, X, R;
δ(q2, 0)=q2, 0, L;
δ(q2, 1)=q2, 1, L;
δ(q0, Y)=q0, Y, R;
δ(q0, B)=q3, B, R;

Figure 6.5: Turing machine for the language L= {ww : w=(0+1)*}.


Different types of Turing Machines
The Turing machine studied so far has simple one to understand the basic operation. By making
use of this knowledge we can construct the complex Turing Machine. They are of
i. Multi-dimensional Turing Machines
ii. Multi-tape Turing Machines
iii. Non-deterministic Turing Machines
i. Multi-dimensional Turing Machines
In this case, Turing machine has multi-dimensional tape, with a read write head. It uses
basic concept of Turing machine with modification of transition function as shown in
figure 6.6.

Page 6.5
TURING MACHINE

δ : Q × Γ→ Q × Γ ×{L, R, U, D},
Where U and D specifies movement of the read-write head up and down.

Figure 6.6: Multi-dimensional Turing Machine.


The basic Turing machine resembles like multi-dimensional Turing machine. It treats
multiple symbols as single symbol, because all symbols are stored in a single cell as
shown in figure 6.7.

Figure 6.7: Turing machine in the form of multi-dimensional Turing Machines.

ii. Multi-tape Turing Machines


Turing machine has multiple tapes, each with its read write head. It uses basic concept of
Turing machine with the modification of transition function as follows.
Q x ∑n=Q , ┌n, {L, R}n
For example, if n = 2, with a current configuration shown in Figure 6.8,
then δ(q0, 0, 1) = (q1, X, Y, L, R)

Figure 6.8: Multi-tape Turing Machines.


The transition rule can be applied only if the machine is in state q0 and the first read-write head
read an 0 and the second an 1. The symbol on the first tape will then be replaced with an X and its
read-write head will move to the left. At the same time, the symbol on the second tape is rewritten
as Y and the read-write head moves right. The control unit then changes its state to q1 and the
machine goes into the new configuration shown in Figure 6.8.
Multi-dimensional uses extra caps to work like a multi-tape. It scans first row from left to right,
whenever it comes across symbol which has a cap, it stop scanning and changes the particular
symbol to tape symbol and move right or left with the cap. Next it scans second row, same actions
are repeated in the second row too as shown in figure 6.9.

Page 6.6
TURING MACHINE

Figure 6.9: Multi-dimensional Turing machine in the form of multi-tape Turing machines.

iii. Non-deterministic Turing Machines


Non-deterministic Turing Machines is similar to deterministic Turing machine, except
the transition function. The transition function is defined as
δ : Q × Γ → 2Q×Γ×{L, R}
If a Turing machine has transitions specified
by δ (q0, t) = {(q1,X, R), (q2,Y, L)},
in NPDA, the moves and are possible.

Page 6.7

You might also like