You are on page 1of 44

History of Theory of Computation

 1936 Alan Turing invented the Turing machine, and proved that there exists an unsolvable
problem.
 1940’s Stored-program computers were built.
 1943 McCulloch and Pitts invented finite automata.
 1956 Kleene invented regular expressions and proved the equivalence of regular expression and
finite automata.
 1956 Chomsky defined Chomsky hierarchy, which organized languages recognized by
different automata into hierarchical classes.
 1959 Rabin and Scott introduced nondeterministic finite automata and proved its equivalence to
(deterministic) finite automata.
 1950’s-1960’s More works on languages, grammars, and compilers.
 1965 Hartmantis and Stearns defined time complexity, and Lewis, Hartmantis and Stearns
defined space complexity.
 1971 Cook showed the first NP-complete problem, the satisfiability problem.
Motivation
Our main goal in this course is to analyze problems and categorize them according to their
complexity.
The Language Hierarchy

They are more powerful than both finite automata and pushdown automata. In fact, they are as
powerful as any computer we have ever built.

Turing Machine Introduction


A Turing Machine is a computing Device that can be
represented as from the following diagram,
A TM consists of three parts
 Infinite Tape
 Read/Write Head
 Finite Control

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Tape:
 It’s divided into no of cells.
 Tape is infinite one.
 A cell can hold a tape symbol or blank space (# )
Finite control:
 A particular instant, finite control is in state.
 States are divided into
 Initial state(q0),
 Intermediate state (q1,q2,q3,q4,…..)
 Halt state (h) (There are two halt states)
 Accept state and Reject State.
Tape Head:
 It’s point to one of the tape cell.
 It’s communicate between infinite tape and finite control.
 It can move one cell to left or right or same position.
Operation on the Tape:
 Read / Scan a symbol on the tape head.
 Write / Update a symbol on the tape head.
 Move the tape head one step to Right.
 Move the tape head one step to Left.

Rules of Operation -1
At each step of the Computation
 Read the current symbol
 Update ( i,e. Write ) the same cell
 Move exactly one cell either Left or Write
If we are at the left end of the tape, and trying to move LEFT, then do not move. Stay at the same
cell.
States & Transitions
Symbol to Read Symbol to Write Direction to move either Left or Right

(ab,R)
Q1 Q2
(aa,R) ‘a’ is replaced with ‘a’ and move towards Right side
Q1 Q2 one cell.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Rules of Operation -2
 Control is looking like FSM
 Initial State
 Final State ( There are two final state )
 Accept state
 Reject State
 Computation can either
1. HALT and ACCEPT
2. HALT and REJECT
3. LOOP ( The Machine fail to HALT)
Definition of Turing Machine
Turing Machine can be defined as a set of seven Tuples
TM = ( Q, ∑, Γ, δ, q0, #, h)
Q  Non empty set of states.
∑  Non empty set of input symbol.
Γ  Non empty set of tape symbol.
δ  Transition function defined as
( Q x Γ )  ( Q x Γ x { L, R, N } )
q0  is a initial state.
#  is a blank symbol.
h  is a halt state.
TM instructions ( Transition functions )
Each Turing machine instruction contains the following five parts:
 The current machine state.
 A tape symbol read from the current tape cell.
 A tape symbol to write into the current tape cell.
 The next machine state.
 A direction for the tape head to move.
Example
Consider the following TM The current state is q1 and current character is
x y a M b # # ‘y’, then ‘y’ is replaced by ‘y’, moves one cell
towards right (R) and reached q1 state.
q0 a y a m b # #
Here TM is in state, q0 and head points to tape
symbol, ‘x’. q1
Let move is defined as δ(q0, x) = (q1,a, R) Here TM is in state, q1 and head points to tape
The current state is q0 and current character is symbol, ‘a’.
‘x’, then ‘x’ is replaced by ‘a’, moves one cell Let move is defined as δ(q1, a) = (q2,b, L)
towards right (R) and reached q1 state. The current state is q1 and current character is
a y a M b # # ‘a’, then ‘a’ is replaced by ‘b’, moves one cell
towards left (L) and reached q2 state.
q1 a y b m b # #
Here TM is in state, q1 and head points to tape
symbol, ‘y’. q2
Let move is defined as δ(q1, y) = (q1,y, R)

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Example 1: Example 2:
Consider the following Turing Machine Consider the following Turing Machine
TM = ( Q, ∑, Γ, δ, q0, #, h) TM = ( Q, ∑, Γ, δ, q0, #, h)
,Where Q={q1,q2,q3,q4,q5,q6}, ,Where Q={q1,q2,q3,q4,q5,q6},
∑={0,1,x,y}, Γ={0,1,x,y,#}, ∑={0,1,x,y}, Γ={0,1,x,y,#},
Q0=q1, Q0=q1,
#=#, #=#,
h=q6. h=q6.
δ is defined as follow as δ is defined as follow as
δ(q1,0)=(q2,x,R), δ(q1,#)=(q5,#,R), δ(q1,0)=(q2,x,R), δ(q1,#)=(q5,#,R),
δ(q2,0)=(q2,0,R), δ(q2,1)=(q3,y,L), δ(q2,0)=(q2,0,R), δ(q2,1)=(q3,y,L),
δ(q2,y)=(q2,y,R), δ(q3,0)=(q4,0,L), δ(q2,y)=(q2,y,R), δ(q3,0)=(q4,0,L),
δ(q3,x)=(q5,x,R), δ(q3,y)=(q3,y,L), δ(q3,x)=(q5,x,R), δ(q3,y)=(q3,y,L),
δ(q4,0)=(q4,0,L), δ(q4,x)=(q1,x,R), δ(q4,0)=(q4,0,L), δ(q4,x)=(q1,x,R),
δ(q5,y)=(q5,x,R), δ(q5,#)=(q6,#,R). δ(q5,y)=(q5,x,R), δ(q5,#)=(q6,#,R).
Check whether the string 011 is accepted by Check whether the string 0011 is accepted by
above TM. above TM.
Initially, TM is in start state, q1 and the tape Initially, TM is in start state, q1 and the tape
contains the given string 011. Initially, head contains the given string 0011. Initially, head
points to the symbol 0 in the input string. points to the symbol 0 in the input string.
0 1 1 # # # # 0 0 1 1 # # #

Q1 Q1
A given transition function is δ(q1,0)=(q2,x,R), A given transition function is δ(q1,0)=(q2,x,R),
Then TM becomes Then TM becomes
x 1 1 # # # # x 0 1 1 # # #

Q2 Q2
A given transition function is δ(q2,1)=(q3,y,L), A given transition function is δ(q2,0)=(q2,0,R),
Then TM becomes Then TM becomes
x y 1 # # # # x 0 1 1 # # #

Q3 Q2
A given transition function is δ(q3,x)=(q5,x,R), A given transition function is δ(q2,1)=(q3,y,L),
Then TM becomes Then TM becomes
x y 1 # # # # x 0 y 1 # # #

Q5 Q3
A given transition function is δ(q5,y)=(q5,x,R), A given transition function is δ(q3,0)=(q4,0,L),
Then TM becomes Then TM becomes
x x 1 # # # # x 0 y 1 # # #

Q5 Q4
δ(q5,1) is not defined for the TM. So the string A given transition function is δ(q4,x)=(q1,x,R),
011 is not accepted by the above TM Then TM becomes

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
x 0 Y 1 # # # Example 3:
Consider the following Turing Machine
Q1
TM = ( Q, ∑, Γ, δ, q0, #, h)
A given transition function is δ(q1,0)=(q2,x,R),
,Where
Then TM becomes
Q={q1,q2,q3,q4,q5,q6},
x x y 1 # # #
∑={0,1,x,y},
Q2 Γ={0,1,x,y,#},
A given transition function is δ(q2,y)=(q2,y,R), Q0=q1,
Then TM becomes #=#,
x x y 1 # # # h=q6.
δ is defined as follow as
Q2 δ(q1,0)=(q2,x,R), δ(q1,#)=(q5,#,R),
A given transition function is δ(q2,1)=(q3,y,L),
δ(q2,0)=(q2,0,R), δ(q2,1)=(q3,y,L),
Then TM becomes
δ(q2,y)=(q2,y,R), δ(q3,0)=(q4,0,L),
x x y y # # #
δ(q3,x)=(q5,x,R), δ(q3,y)=(q3,y,L),
Q3 δ(q4,0)=(q4,0,L), δ(q4,x)=(q1,x,R),
A given transition function is δ(q3,y)=(q3,y,L), δ(q5,y)=(q5,x,R), δ(q5,#)=(q6,#,R).
Then TM becomes Check whether the string 001 is accepted by
x x y y # # # above TM.
Initially, TM is in start state, q1 and the tape
Q3 contains the given string 001. Initially, head
A given transition function δ(q3,x)=(q5,x,R), points to the symbol 0 in the input string.
Then TM becomes 0 0 1 # # # #
x x y y # # #
Q1
Q5 A given transition function is δ(q1,0)=(q2,x,R),
A given transition function δ(q5,y)=(q5,x,R), Then TM becomes
Then TM becomes x 0 1 # # # #
x x x y # # #
Q2
Q5 A given transition function is δ(q2,0)=(q2,0,R),
A given transition function δ(q5,y)=(q5,x,R), Then TM becomes
Then TM becomes x 0 1 # # # #
x x x x # # #
Q2
Q5 A given transition function is δ(q2,1)=(q3,y,L),
A given transition function δ(q5,#)=(q6,#,R). Then TM becomes
Then TM becomes x 0 y # # # #
x x x x # # #
Q3
Q6 A given transition function is δ(q3,0)=(q4,0,L),
Q6 is the halt state or accepting state of the Then TM becomes
TM. So the given string 0011 is accepted x 0 Y # # # #
by the above TM.
Q4

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q4,x)=(q1,x,R), x Q201###
Then TM becomes
x 0 y # # # # x 0 1 # # # #

Q1 Q2
A given transition function is δ(q1,0)=(q2,x,R), x0 Q21###
Then TM becomes x 0 y # # # #
x x y # # # #
Q3
Q2 xQ30y###
A given transition function is δ(q2,y)=(q2,y,R), x 0 Y # # # #
Then TM becomes
x x y # # # # Q4
Q4x0y###
Q2 x 0 y # # # #
Now TM halts because no δ is defined for Q2
and #. But Q2 is not the halt state of TM. So the Q1
x Q10y###
given string 001 is not accepted by the above
x x Y # # # #
TM.
Representation of Turing Machine Q2
We are represent a TM in different ways. They xx Q2y###
are x x Y # # # #
 Instantaneous Descriptions
 Transition Table Q2
 Transition Diagram xxy Q2###
This transition from one state to other can be
Representation of TM Instantaneous written as
Descriptions Q1001### ├ x Q201###
In all the above examples, TM shown in the
picture was instantaneous descriptions. This Instantaneous Descriptions sequence for the
means an instant of a TM is shown. above TM (Example 3) is given below
Let us take example 3 for instantaneous Q1001### ├ xQ201### ├ x0Q21### ├
descriptions of TM. Now we will discuss xQ30y### ├ Q4x0y### ├ xQ10y### ├
xx Q2y### ├ xxyQ2###
Instantaneous Descriptions  before the
Current Symbol + Current State + from Transition Table for the above TM (Example
Current Symbol to Blank Symbol. 3) is given below
0 1 x y #
q1 (q2,x,R) (q5,#,R)
0 0 1 # # # # q2 (q2,0,R) (q3,y,L) (q2,y,R)
q3 (q4,0,L) (q5,x,R) (q3,y,L)
Q1 q4 (q4,0,L) (q1,x,R)
q5 (q5,x,R) (q6,#,R)
Q1001### *q6
x 0 1 # # # #

Q2
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Transition Diagram for the above TM a a a # # # #
(Example 3) is given below
Q0
A given transition function is δ(q0,a)=(q1,a,R),
Then TM becomes
a a a # # # #

Q1
If the blank symbol is reached in q1 state. It
indicates that input string contains an odd no of
a’s.
Example 2:
Designing a Turing Machine over {a} to accept
the language L = { an | n is even }.
Transition Table is given below
Input Symbol
Designing of Turing Machines Current state
A #
Following are the basic guide lines for *q0 (q1,a,R) -
designing of TM q1 (q0,a,R) -
The fundamental objective of scanning a
symbol in the tape is to know what to do the a a a A # # #
future. TM must remember the past symbol
Q0
scanned. TM can remember this by going to the
A given transition function is δ(q0,a)=(q1,a,R),
next unique state.
Then TM becomes
The number of state must be minimized. This
a a a a # # #
is achieved by changing the states only when
there is a change in the written symbol or when Q1
there is a change in the movement of the head. A given transition function is δ(q1,a)=(q0,a,R),
Example 1: Then TM becomes
Designing a Turing Machine over {a} to accept a a a a # # #
the language L = { an | n is odd }.
Q0
Input Symbol
Current state A given transition function is δ(q0,a)=(q1,a,R),
A #
q0 (q1,a,R) - Then TM becomes
*q1 (q0,a,R) - a a a a # # #

Q1
a A a # # # #
A given transition function is δ(q1,a)=(q0,a,R),
Q0 Then TM becomes
A given transition function is δ(q0,a)=(q1,a,R), a a a a # # #
Then TM becomes
Q0
a a a # # # #
If the blank symbol is reached in q0 state. It
Q1 indicates that input string contains an even no
A given transition function is δ(q1,a)=(q0,a,R), of a’s.
Then TM becomes
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Example 3: 1 0 1 # # # #
Designing a Turing Machine over { a, b} to
accept the language L = { ending with b }. Q0
A given transition function is δ(q0,1)=(q0,1,R),
L = { b, ab bbb, ababab……}
Then TM becomes
Transition function are given below.
1 0 1 # # # #
δ(q0,a)=(q0,a,R) δ(q0,b)=(q0,b,R)
δ(q0,#)=(q1,#,L) δ(q1,b)=(qf,b,R) Q0
a b b # # # # A given transition function is δ(q0,0)=(q0,0,R),
Then TM becomes
Q0
1 0 1 # # # #
A given transition function is δ(q0,a)=(q0,a,R),
Then TM becomes Q0
a b b # # # # A given transition function is δ(q0,1)=(q0,1,R),
Then TM becomes
Q0 a b b # # # #
A given transition function is δ(q0,b)=(q0,b,R),
Then TM becomes Q0
a b b # # # # A given transition function is δ(q0,#)=(q1,#,L),
Then TM becomes
Q0
1 0 1 # # # #
A given transition function is δ(q0,b)=(q0,b,R),
Then TM becomes Q1
a b b # # # # A given transition function is δ(q1,1)=(qf,1,R),
Then TM becomes
Q0
1 0 1 # # # #
A given transition function is δ(q0,#)=(q1,#,L),
Then TM becomes Qf
a b b # # # # The input string odd no equivalent to binary
form is accepted by the above TM.
Q1
Example 5:
A given transition function is δ(q1,b)=(qf,b,R),
Designing a Turing Machine over { 0, 1} to
Then TM becomes
accept the language L = { all even no’s
a b b # # # #
equivalent to binary form}.
Qf L = { 0,10,100,110,1000,1010,1100,1110…}
The input string ending b is accepted by the Check given string 110 accepted or not
above TM. Transition function are given below.
Example 4: δ(q0,1)=(q0,1,R) δ(q0,0)=(q0,0,R)
Designing a Turing Machine over { 0, 1} to δ(q0,#)=(q1,#,L) δ(q1,1)=(qf,b,R)
accept the language L = { all odd no’s 1 1 0 # # # #
equivalent to binary form}.
L = { 1,11,101,111,1001,1011,1101,1111….} Q0
A given transition function is δ(q0,1)=(q0,1,R),
Check given string 101 accepted or not
Then TM becomes
Transition function are given below.
1 1 0 # # # #
δ(q0,1)=(q0,1,R) δ(q0,0)=(q0,0,R)
δ(q0,#)=(q1,#,L) δ(q1,1)=(qf,b,R) Q0
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q0,1)=(q0,1,R), A given transition function is δ(q1,1)=(q1,y,R),
Then TM becomes Then TM becomes
1 1 0 # # # # x y y 0 # # #

Q0 Q1
A given transition function is δ(q0,0)=(q0,0,R), A given transition function is δ(q1,0)=(q2,x,R),
Then TM becomes Then TM becomes
1 1 0 # # # # x y y x # # #

Q0 Q2
A given transition function is δ(q0,#)=(q1,#,L), A given transition function is δ(q2,#)=(qA,#,R),
Then TM becomes Then TM becomes
1 1 0 # # # # x y y x # # #

Q1 QA
A given transition function is δ(q1,0)=(qf,0,R), The given string 0110 accepted by above TM.
Then TM becomes Example 7:
1 0 1 # # # # Designing a Turing Machine over { a, b} to
accept the language L = { anbn | n>=1 }.
Qf Check given string 0011 accepted or not
The input string even no equivalent to binary
Algorithm:
form is accepted by the above TM.
 Change “0” to “x”
 Move Right to First “1”
Example 6:
 If None : Rejected
Designing a Turing Machine over { 0, 1} to
 Change “1” to “y”
accept the language L = { 01*0 }.
 Move Left to Leftmost “0”
Check given string 0110 accepted or not
 Repeat the above steps Until no More “0” s
Transition function are given below.
 Make sure no more “1” s remain,
δ(q0,0)=(q1,x,R) δ(q1,0)=(q2,x,R)
Transition function are given below.
δ(q1,1)=(q1,y,R) δ(q2,#)=(qA,#,R)
δ(q0,0)=(q1,x,R) δ(q1,0)=(q1,0,R)
δ(q0,1)=(qR,1,R) δ(q0,#)=(qR,#,R)
δ(q1,y)=(q1,y,R) δ(q1,1)=(q2,y,L)
δ(q1,#)=(qR,#,R) δ(q2,1)=(qR,1,R)
δ(q2,0)=(q2,0,L) δ(q2,y)=(q2,y,L)
δ(q2,0)=(qR,0,R)
δ(q2,x)=(q0,x,R) δ(q0,y)=(q3,y,R)
0 1 1 0 # # #
δ(q3,y)=(q3,y,R) δ(q3,#)=(qA,#,L)
Q0 δ(q0,#)=(qA,#,L)
A given transition function is δ(q0,0)=(q1,x,R), 0 0 1 1 # # #
Then TM becomes
x 1 1 0 # # # Q0
A given transition function is δ(q0,0)=(q1,x,R),
Q1 Then TM becomes
A given transition function is δ(q1,1)=(q1,y,R), x 0 1 1 # # #
Then TM becomes
x y 1 0 # # # Q1
A given transition function is δ(q1,0)=(q1,0,R),
Q1 Then TM becomes

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
x 0 1 1 # # # A given transition function is δ(q3,y)=(q3,y,R),
Then TM becomes
Q1 x x y y # # #
A given transition function is δ(q1,1)=(q2,y,L),
Then TM becomes Q3
x 0 y 1 # # # A given transition function is δ(q3,#)=(qA,#,L),
Then TM becomes
Q2 x x y y # # #
A given transition function is δ(q2,0)=(q2,0,L),
Then TM becomes QA
x 0 y 1 # # # The given string 0011 is accept by above TM.
Example 7:
Q2 Designing a Turing Machine over { a, b} to
A given transition function is δ(q2,x)=(q0,x,R),
accept the language L = { anbncn | n>=1 }.
Then TM becomes
Check given string aabbcc accepted or not
x 0 y 1 # # #
Transition function are given below.
Q0 δ(q0,a)=(q1,x,R) δ(q1,a)=(q1,a,R)
A given transition function is δ(q0,0)=(q1,x,R), δ(q1,y)=(q1,y,R) δ(q1,b)=(q2,y,R)
Then TM becomes δ(q2,z)=(q2,z,R) δ(q2,b)=(q2,b,R)
x x y 1 # # # δ(q2,c)=(q3,z,L) δ(q3,a)=(q3,a,L)
δ(q3,y)=(q3,y,L) δ(q3,b)=(q3,b,L)
Q1
δ(q3,z)=(q3,z,L) δ(q3,x)=(q0,x,R)
A given transition function is δ(q1,y)=(q1,y,R),
δ(q0,y)=(q4,y,R) δ(q4,y)=(q4,y,R)
Then TM becomes
δ(q4,z)=(q4,z,R) δ(q4,#)=(qA,#,L)
x x y 1 # # #
a a b b c c #
Q1
Q0
A given transition function is δ(q1,1)=(q2,y,L),
A given transition function is δ(q0,a)=(q1,x,R),
Then TM becomes
Then TM becomes
x x y y # # #
x a b b c c #
Q2
Q1
A given transition function is δ(q2,y)=(q2,y,L),
A given transition function is δ(q1,a)=(q1,a,R),
Then TM becomes
Then TM becomes
x x y y # # #
x a b b c c #
Q2
Q1
A given transition function is δ(q2,x)=(q0,x,R),
A given transition function is δ(q1,b)=(q2,y,R),
Then TM becomes
Then TM becomes
x x y y # # #
x a y b c c #
Q0
Q2
A given transition function is δ(q0,y)=(q3,y,R),
A given transition function is δ(q2,b)=(q2,b,R),
Then TM becomes
Then TM becomes
x x y y # # #

Q3
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
x a y b c c # A given transition function is δ(q2,c)=(q3,z,L),
Then TM becomes
Q2 x x y y z z #
A given transition function is δ(q2,c)=(q3,z,L),
Then TM becomes Q3
x a y b z c # x x y y z z #

Q3 Q3
A given transition function is δ(q3,b)=(q3,b,L), A given transition function is δ(q3,z)=(q3,z,L),
Then TM becomes Then TM becomes
x a y b z c # x x y y z z #

Q3 Q3
A given transition function is δ(q3,y)=(q3,y,L), A given transition function is δ(q3,y)=(q3,y,L),
Then TM becomes Then TM becomes
x a y b z c # x x y y z z #

Q3 Q3
A given transition function is δ(q3,a)=(q3,a,L), A given transition function is δ(q3,y)=(q3,y,L),
Then TM becomes Then TM becomes
x a y b z c # x x y y z z #

Q3 Q3
A given transition function is δ(q3,x)=(q0,x,R), A given transition function is δ(q3,x)=(q0,x,R),
Then TM becomes Then TM becomes
x a y b z c # x x y y z z #

Q0 Q0
A given transition function is δ(q0,a)=(q1,x,R), A given transition function is δ(q0,y)=(q4,y,R),
Then TM becomes Then TM becomes
x x y b z c # x x y y z z #

Q1 Q4
A given transition function is δ(q1,y)=(q1,y,R), A given transition function is δ(q4,y)=(q4,y,R),
Then TM becomes Then TM becomes
x x y b z c # x x y y z z #

Q1 Q4
A given transition function is δ(q1,b)=(q2,y,R), A given transition function is δ(q4,z)=(q4,z,R),
Then TM becomes Then TM becomes
x x y y z c # x x y y z z #

Q2 Q4
A given transition function is δ(q2,z)=(q2,z,R), A given transition function is δ(q4,z)=(q4,z,R),
Then TM becomes Then TM becomes
x x y y z c # x x y y z z #

Q2 Q4
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q4,#)=(qA,#,L), # b b a # # #
Then TM becomes
x x y y z z # Q5
A given transition function is δ(q5,a)=(q3,#,L),
QA Then TM becomes
The given string aabbcc is accept by above TM. # b b # # # #

Q3
Example 8:
A given transition function is δ(q3,b)=(q3,b,L),
Designing a Turing Machine over { a, b} to
Then TM becomes
accept the language L = { aa, abba, bb, baab }.
# b b # # # #
Check given string abba is Palindrome or not.
Q3
Transition function is given below. A given transition function is δ(q3,b)=(q3,b,L),
δ(q0,a)=(q4,#,R) δ(q0,b)=(q1,#,R) Then TM becomes
δ(q4,a)=(q4,a,R) δ(q4,b)=(q4,b,R) # b b # # # #
δ(q1,a)=(q1,a,R) δ(q1,b)=(q1,b,R)
Q3
δ(q4,#)=(q5,#,L) δ(q1,#)=(q2,#,L)
A given transition function is δ(q3,#)=(q0,#,R),
δ(q5,a)=(q3,#,L) δ(q2,b)=(q3,#,L)
Then TM becomes
δ(q3,a)=(q3,a,L) δ(q3,b)=(q3,b,L)
# b b # # # #
δ(q3,#)=(q0,#,R) δ(q0,#)=(qA,#,R)
δ(q5,#)=(qA,#,R) δ(q2,#)=(qA,#,R) Q0
a b b a # # # A given transition function is δ(q0,b)=(q1,#,R),
Then TM becomes
Q0
# # b # # # #
A given transition function is δ(q0,a)=(q4,#,R),
Then TM becomes Q1
# b b a # # # A given transition function is δ(q1,b)=(q1,b,R),
Then TM becomes
Q4
# # b # # # #
A given transition function is δ(q4,b)=(q4,b,R),
Then TM becomes Q1
# b b a # # # A given transition function is δ(q1,#)=(q2,#,L),
Then TM becomes
Q4
# # b # # # #
A given transition function is δ(q4,b)=(q4,b,R),
Then TM becomes Q2
# b b a # # # A given transition function is δ(q2,b)=(q3,#,L),
Then TM becomes
Q4
# # # # # # #
A given transition function is δ(q4,a)=(q4,a,R),
Then TM becomes Q3
# b b a # # # A given transition function is δ(q3,#)=(q0,#,R),
Then TM becomes
Q4
# # # # # # #
A given transition function is δ(q4,#)=(q5,#,L),
Then TM becomes Q0
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q0,#)=(qA,#,R), Transition table is given below
Then TM becomes Input symbol
Current State
# # # # # # # 0 $ #
q0 (q0, 0, R) (q1, 0, R) -
QA q1 (q0, 0, R) - (q2, #, L)
The given input string is Palindrome. q2 (qA, #, L) - -
qA - - -
TM as Transducers
In all the above TMs, TM either accepts or 0 0 0 $ 0 0 # # #
rejects a input string. That is TM act as
Q0
language acceptor.
A given transition function is δ(q0,0)=(q0,0,R),
A TM can function as a transducer. That is , a
Then TM becomes
string is given as a input to TM, it produces
0 0 0 $ 0 0 # # #
some output.
We can see a Turing machine as a transducer. Q0
Input to the computation is a set of symbols on A given transition function is δ(q0,0)=(q0,0,R),
the tape. At the end of computation, whatever Then TM becomes
remains on the tape is the output. 0 0 0 $ 0 0 # # #
we can see that all common mathematical
Q0
functions are Turing computable. This means,
A given transition function is δ(q0,0)=(q0,0,R),
basic operations such as addition, subtraction,
Then TM becomes
multiplication, division can be performed on it.
0 0 0 $ 0 0 # # #
This means that a TM is an abstract model of
our modern computer system. Q0
A given transition function is δ(q0,$)=(q1,0,R),
Example 1: Then TM becomes
Design a TM that computes the following 0 0 0 0 0 0 # # #
function, f( m, n ) = m + n.
Q1
A positive integer on a TM tape can be
A given transition function is δ(q1,0)=(q1,0,R),
represented by equal number of 0s.
Then TM becomes
For example
0 0 0 0 0 0 # # #
Integer 5 is represented as 00000 and integer
12 is represented as 000000000000. Q1
In the tape two integer are separated using the A given transition function is δ(q1,0)=(q1,0,R),
symbol $. Then TM becomes
Let as assume m = 3 and n = 2. Then the input 0 0 0 0 0 0 # # #
tape of the TM will be
Q1
0 0 0 $ 0 0 # # #
A given transition function is δ(q1,#)=(q2,#,L),
Then TM becomes
After the addition, tape will contain the result of
0 0 0 0 0 0 # # #
addition is given below.
Q2
0 0 0 0 0 # # # #

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q2,0)=(qA,#,L), A given transition function is δ(q3,0)=(q3,0,R),
Then TM becomes Then TM becomes
0 0 0 0 0 # # # # # x $ y 0 0 $ # # # # #

QA Q3
After the addition, tape will contain 00000. So A given transition function is δ(q3,0)=(q3,0,R),
result of addition is five. Then TM becomes
Example 2: # x $ y 0 0 $ # # # # #
Design a TM that computes the following
Q3
function, f( m, n ) = m * n.
A given transition function is δ(q3,$)=(q4,$,R),
Let as assume m = 1 and n = 3. Then the input
Then TM becomes
tape of the TM will be
# x $ y 0 0 $ # # # # #
# 0 $ 0 0 0 $ # # # # #
After the addition, tape will contain the result of Q4
addition is given below. A given transition function is δ(q4,#)=(q5,0,L),
# 0 $ 0 0 0 $ 0 0 0 # # Then TM becomes
Transition function is given below # x $ y 0 0 $ 0 # # # #
δ(q0,0)=(q1,x,R) δ(q0,$)=(q9,$,L)
δ(q1,0)=(q1,0,R) δ(q1,$)=(q2,$,R) Q5
δ(q2,0)=(q3,y,R) δ(q2,$)=(q7,$,L) A given transition function is δ(q5,$)=(q6,$,L),
δ(q3,0)=(q3,0,R) δ(q3,$)=(q4,$,R) Then TM becomes
δ(q4,0)=(q4,0,R) δ(q4,#)=(q5,0,L) # x $ y 0 0 $ 0 # # # #
δ(q5,0)=(q5,0,L) δ(q5,$)=(q6,$,L)
Q6
δ(q6,0)=(q6,0,L) δ(q6,y)=(q2,y,R) A given transition function is δ(q6,0)=(q6,0,L),
δ(q7,$)=(q8,$,L) δ(q7,y)=(q7,0,L) Then TM becomes
δ(q8,0)=(q8,0,L) δ(q8,x)=(q0,x,R) # x $ y 0 0 $ 0 # # # #
δ(q9,x)=(q9,0,L) δ(q9,#)=(qA,#,R)
# 0 $ 0 0 0 $ # # # # # Q6
A given transition function is δ(q6,0)=(q6,0,L),
Q0 Then TM becomes
A given transition function is δ(q0,0)=(q1,x,R), # x $ y 0 0 $ 0 # # # #
Then TM becomes
# x $ 0 0 0 $ # # # # # Q6
A given transition function is δ(q6,y)=(q2,y,R),
Q1 Then TM becomes
A given transition function is δ(q1,$)=(q2,$,R), # x $ y 0 0 $ 0 # # # #
Then TM becomes
# x $ 0 0 0 $ # # # # # Q2
A given transition function is δ(q2,0)=(q3,y,R),
Q2 Then TM becomes
A given transition function is δ(q2,0)=(q3,y,R), # x $ y y 0 $ 0 # # # #
Then TM becomes
# x $ y 0 0 $ # # # # # Q3
A given transition function is δ(q3,0)=(q3,0,R),
Q3 Then TM becomes

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
# x $ y y 0 $ 0 # # # # # x $ y y y $ 0 0 # # #

Q3 Q4
A given transition function is δ(q3,$)=(q4,$,R), A given transition function is δ(q4,0)=(q4,0,R),
Then TM becomes Then TM becomes
# x $ y y 0 $ 0 # # # # # x $ y y y $ 0 0 # # #

Q4 Q4
A given transition function is δ(q4,0)=(q4,0,R),
A given transition function is δ(q4,0)=(q4,0,R), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 # # #
# x $ y y 0 $ 0 # # # #
Q4
Q4 A given transition function is δ(q4,#)=(q5,0,L),
A given transition function is δ(q4,#)=(q5,0,L), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 0 # #
# x $ y y 0 $ 0 0 # # #
Q5
Q5 A given transition function is δ(q5,0)=(q5,0,L),
A given transition function is δ(q5,0)=(q5,0,L), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 0 # #
# x $ y y 0 $ 0 0 # # #
Q5
Q5 A given transition function is δ(q5,0)=(q5,0,L),
A given transition function is δ(q5,$)=(q6,$,L), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 0 # #
# x $ y y 0 $ 0 0 # # #
Q5
Q6 A given transition function is δ(q5,$)=(q6,$,L),
A given transition function is δ(q6,0)=(q6,0,L), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 0 # #
# x $ y Y 0 $ 0 0 # # #
Q6
Q6 A given transition function is δ(q6,y)=(q2,y,R),
A given transition function is δ(q6,y)=(q2,y,R), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 0 # #
# x $ y y 0 $ 0 0 # # #
Q2
Q2 A given transition function is δ(q2,$)=(q7,$,L),
A given transition function δ(q2,0)=(q3,y,R), Then TM becomes
Then TM becomes # x $ y y y $ 0 0 0 # #
# x $ y y y $ 0 0 # # #
Q7
Q3 A given transition function is δ(q7,y)=(q7,0,L),
A given transition function δ(q3,$)=(q4,$,R), Then TM becomes
Then TM becomes # x $ y y 0 $ 0 0 0 # #

Q7
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q7,y)=(q7,0,L), Transition Table is given below
Then TM becomes Input symbol
Current State
# x $ y 0 0 $ 0 0 0 # # 1 x #
q0 (q0, x, R) (q1, #, L)
Q7 q1 (q1, 1, L) (q2, 1, R) (qA, #, R)
A given transition function is δ(q7,y)=(q7,0,L), q2 (q2, 1, R) - (q1, 1, L)
Then TM becomes qA - - -
# x $ 0 0 0 $ 0 0 0 # #
# 1 1 # # # #
Q7
A given transition function is δ(q7,$)=(q8,$,L), Q0
Then TM becomes A given transition function is δ(q0,1)=(q0,x,R),
# x $ 0 0 0 $ 0 0 0 # # Then TM becomes
# x 1 # # # #
Q8
A given transition function is δ(q8,x)=(q0,x,R), Q0
Then TM becomes A given transition function is δ(q0,1)=(q0,x,R),
# x $ 0 0 0 $ 0 0 0 # # Then TM becomes
# x x # # # #
Q0
A given transition function is δ(q0,$)=(q9,$,L), Q0
Then TM becomes A given transition function is δ(q0,#)=(q1,#,L),
# x $ 0 0 0 $ 0 0 0 # # Then TM becomes
# x x # # # #
Q9
A given transition function is δ(q9,x)=(q9,0,L), Q1
Then TM becomes A given transition function is δ(q1,x)=(q2,1,R),
# 0 $ 0 0 0 $ 0 0 0 # # Then TM becomes
# x 1 # # # #
Q9
A given transition function is δ(q9,#)=(qA,#,R), Q2
Then TM becomes A given transition function is δ(q2,#)=(q1,1,L),
# 0 $ 0 0 0 $ 0 0 0 # # Then TM becomes
# x 1 1 # # #
QA
After the multiplication, tape will contain Q1
#0$000$000##. So result of addition is Three. A given transition function is δ(q1,1)=(q1,1,L),
Then TM becomes
Example 3: # x 1 1 # # #
Design a TM that copies string of 1s
Q1
Let as assume input string #11####. Then tape
A given transition function is δ(q1,x)=(q2,1,R),
of the TM will be
Then TM becomes
# 1 1 # # # #
# 1 1 1 # # #

The output of the TM will be #1111## Q2


# 1 1 1 1 # #

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A given transition function is δ(q2,1)=(q2,1,R), δ(q2,0)=(qA,1,L)
Then TM becomes # 1 1 0 1 # # #
# 1 1 1 # # #
Q0
Q2
A given transition function is δ(q0,1)=(q1,#,R),
A given transition function is δ(q2,1)=(q2,1,R),
Then TM becomes
Then TM becomes
# 1 1 1 # # # # # 1 0 1 # # #

Q2 Q1
A given transition function is δ(q2,#)=(q1,1,L), A given transition function is δ(q1,1)=(q1,1,R),
Then TM becomes Then TM becomes
# 1 1 1 1 # # # # 1 0 1 # # #
Q1
A given transition function is δ(q1,1)=(q1,1,L), Q1
Then TM becomes A given transition function is δ(q1,0)=(q1,0,R),
# 1 1 1 1 # # Then TM becomes
# # 1 0 1 # # #
Q1
A given transition function is δ(q1,1)=(q1,1,L),
Q1
Then TM becomes
A given transition function is δ(q1,1)=(q1,1,R),
# 1 1 1 1 # #
Then TM becomes
Q1 # # 1 0 1 # # #
A given transition function is δ(q1,1)=(q1,1,L),
Then TM becomes Q1
# 1 1 1 1 # # A given transition function is δ(q1,#)=(q2,#,L),
Then TM becomes
Q1
A given transition function is δ(q1,#)=(qA,#,R), # # 1 0 1 # # #
Then TM becomes
# 1 1 1 1 # # Q2
A given transition function is δ(q2,1)=(q3,#,L),
QA Then TM becomes
The string #11#### was copied #1111##. # # 1 0 # # # #

Example 4: Q3
Design a TM that computes the following A given transition function is δ(q3,0)=(q3,0,L),
function, f( m, n ) = m - n. L ={ m>=n | m-n } Then TM becomes
Let as assume m = 2 and n = 1.
# # 1 0 # # # #
Transition function is given below
δ(q0,1)=(q1,#,R) δ(q1,0)=(q1,0,R)
Q3
δ(q1,1)=(q1,1,R) δ(q1,#)=(q2,#,L)
A given transition function is δ(q3,1)=(q3,1,L),
δ(q2,1)=(q3,#,L) δ(q3,1)=(q3,1,L)
Then TM becomes
δ(q3,0)=(q3,0,L) δ(q3,#)=(q0,#,R)

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
# # 1 0 # # # #

Q3
A given transition function is δ(q3,#)=(q0,#,R),
Then TM becomes
# # 1 0 # # # #

Q0
A given transition function is δ(q0,1)=(q1,#,R),
Then TM becomes
# # # 0 # # # #

Q1
A given transition function is δ(q1,0)=(q1,0,R),
Then TM becomes
# # # 0 # # # #

Q1
A given transition function is δ(q1,#)=(q2,#,L),
Then TM becomes
# # # 0 # # # #

Q2
A given transition function is δ(q2,0)=(qA,1,L),
Then TM becomes
# # # 1 # # # #

Q2
After the subtraction, tape will contain
###1####. So final result is one.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
TYPE OF TURING MACHINE
TWO WAY INFINITY TURING MACHING
The TM we discussed so far had a tape that was finite on the left end. The two ways
infinite TM is an extension to this such that tape is infinite on both side. That is shown
below

Thus on both sides on the tape, there is an infinite sequence of blank symbol on both
side. This model does not provide any additional computational capability.

MULTITAPE TURING MACHINE


A multitape Turing machine is like an ordinary Turing machine with several tapes. Each
tape has its own head for reading and writing. Initially the input appears on tape 1, and
the others start out blank. The transition function is changed to allow for reading,
writing, and moving the heads on some or all of the tapes simultaneously. Formally, it is
δ: ( Q x ΓK )  ( Q x ΓK x { L, R, N } )
where k is a number of tapes. The expression is
δ(qi, a1, . . . , ak) = (qj, b1, . . . , bk, L, R, . . . , L)
means that if the machine is in state qi and heads 1 through k are reading symbols a1
through ak, the machine goes to state qj, writes symbols b1 through bk, and directs each
head to move left or right, or to stay put, as specified.
Multitape Turing machines appear to be more powerful than ordinary Turing machines,
but we can show that they are equivalent in power. Recall that two machines are
equivalent if they recognize the same language.
 Every multitape Turing machine has an equivalent single-tape Turing machine.

PROOF We show how to convert a multitape TM M to an equivalent single-tape TM S.


The key idea is to show how to simulate M with S.
Say that M has k tapes. Then S simulates the effect of k tapes by storing their
information on its single tape. It uses the new symbol # as a delimiter to separate the
contents of the different tapes. In addition to the contents of these tapes, S must keep
track of the locations of the heads. It does so by writing a tape
symbol with a dot above it to mark the place where the head on that tape would be.
Think of these as “virtual” tapes and heads. As before, the “dotted” tape symbols are
simply new symbols that have been added to the tape alphabet. The following figure
illustrates how one tape can be used to represent three tapes.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
NONDETERMINISTIC TURING MACHINES.
A nondeterministic Turing machine is defined in the expected way. At any point in a
computation, the machine may proceed according to several possibilities. The transition
function for a nondeterministic Turing machine has the form
δ : Q × ΓP(Q × Γ × {L, R}).
The computation of a nondeterministic Turing machine is a tree whose branches
correspond to different possibilities for the machine. If some branch of the computation
leads to the accept state, the machine accepts its input. Now we show that Non
Determinism does not affect the power of the Turing machine model.
Every nondeterministic Turing machine has an equivalent deterministic Turing machine.

ENUMERATORS
An enumerator is a Turing machine with an attached printer. The Turing machine can
use that printer as an output device to print strings. Every time the Turing machine
wants to add a string to the list, it sends the string to the printer.
An enumerator E starts with a blank input on its work tape. If the enumerator doesn’t
halt, it may print an infinite list of strings. The language enumerated by E is the
collection of all the strings that it eventually prints out. Moreover, E may generate the
strings of the language in any order, possibly with repetitions. Now we are ready to
develop the connection between enumerators and Turing recognizable languages.

A language is Turing-recognizable if and only if some enumerator enumerates it.


PROOF First we show that if we have an enumerator E that enumerates a language A, a
TM M recognizes A. The TM M works in the following way.
M = “On input w:
1. Run E. Every time that E outputs a string, compare it with w.
2. If w ever appears in the output of E, accept.”

UNIVERSAL TURING MACHINE


In the previous section, a separate TM designed for each Language. For example, for the
language L=(anbn|n>=1) we designed a TM. for the language L=(anbncn|n>=1) we
designed another TMand so on.
A Universal Turing Machine takes of the code normal TM and a string w. and checks
whether w is recognized by TM.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Consider the following TM
TM = ( Q, ∑, Γ, δ, q0, #, h)
,Where
Q={q0,q1,qf },
∑={a,b},
Γ={a,b,,#},
Q0=q0,
#=#,
h=qf.
Transition function are defined as
δ(q0,a)=(q0,a,R)
δ(q0,b)=(q0,b,R)
δ(q0,#)=(q1,#,L)
δ(q1,b)=(qf,b,R)
the codes of the TM is to be made
first we encode all the components of this TM using binary coding. In the binary coding
only symbols 0 and 1are avaiable. Here 0 is used for transition function and 1 is used
for seperator.
States of the TM are
Q={q0,q1,qf }
States can be coded as
Q0=0
Q1=00
Qf=000
Tape symbols are
Γ={a,b,,#}
Tape symbols can be coded
a=0
b=00
#=000
Direction of motion can be coded
L=0
R=00
Transition function are coded
δ(q0,a)=(q0,a,R) = 0101010100
δ(q0,b)=(q0,b,R) = 010010100100
δ(q0,#)=(q1,#,L) = 01000100100010
δ(q1,b)=(qf,b,R) = 001001000100100
in the coding of TM, TM end with 111, transition functions are separator by 11. State,
tape symbol and direction are separator by 1.
Completed TM is
010101010011010010100100110100010010001011001001000100100111.
Let w=abbb be the string to be checked on the TM, M. the input UTM will be,
0101100100100110100010010000101100100010001000010011000100001000010000
01001100001000101000010111abbb

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
UTM uses the binary code of the Turing machine ,M on string abbb and will check. if
true UTM will halt to say yes and if false UTM will stop to say no.

Church’s Thesis:
Several variation on Turing machings, those are given below
 Single tape and one end infinite TMs.
 Single tape and both end infinite TMs.
 Multi tape and one end infinite TMs.
 Multi tape and both end infinite TMs.
 Tiny Alphabet { 0, 1 } or Not
 Can head also place in the same place.
 Deterministic Turing machine.
 Non Deterministic Turing machine.
All variations are equivalent in computing capability.
This is also called Church’s Turing Thesis.
Church’s thesis states that A function said to be computable if it can be computed by a
Turing Machine. This thesis talks about mechanical computation devices and the kind
of computations they can perform. Some more definitions of this thesis are given below
 Any mechanical computation can be performed by a Turing Machine.
 For every computational problem, there is a corresponding Turing Machine.
 Turing machines can be used to model of any mechanical computer.
 The set of languages that can be decided by a TM is the same as that which can be
decided by any computing machine.
 If there is no TM that decides problem P, there is no algorithm that can solve problem
P.
Conculution or Definiton
Algothemically computable are equal to computable by a Turing machine

Godelization:
Godelization is a encoding technique which encodes a string as a number. This is called
Godel numbering. Godel numbering is based on the concept that every positive integer
can be factored into a unique set of prime factor. For example.
6 = 2 * 3;
8 = 2 * 2 * 2;
9 = 3 * 3;
10 = 2 * 5;
20 = 2 * 2 * 5;
30 = 2 * 3 * 5;
50 = 2 * 5 * 5;
100 = 2 * 2 * 5 * 5;
571725 = 3 * 3 * 3 * 5 * 5 * 7 * 11 * 11;
Also its possible to assign a serial number to each prime number, as
1 to 2
2 to 3
3 to 5
4 to 5
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
7 to 11 and so on. Now the number.
571725 = 3*3*3*5*5*7*11*11=20 x 33 x 52 x 70 x 112 can be represented in the form of
a sequence (0,3,2,1,2). In terms of Godel numbering. We say that the Godel number
associated with the sequence (0,3,2,1,1) is 571725.

POST CORRESPONDENCE PROBLEM


Post Correspondence Problem (PCP) is formulated by E.Post in the year 1940.
Example 1:
Let there be two series of string, say x and y series as shown below.
i xi yi
1 10 101
2 01 100
3 0 10
4 100 0
5 1 010
Both x and y series contain 5 strings.
Let as call the string in x series as x substring and the string in y series as y substring
If we concatenate substrings X1X5X2X3X4X4X3X4 and we get
1010101001000100
If we concatenate substrings Y1Y5Y2Y3Y4Y4Y3Y4 and we get
1010101001000100
Let call these string called X string and Y string. It can be seen that x string and y string
are same.
Here we say that this instance of PCP has a solution in the form 15234434.

Linear Bound Automata.


Context sensitive language (Type 1) are produce Context sensitive grammars. Context
sensitive grammars are recognize using Linear Bound Automata (LBA).
The following are example of Context sensitive grammar:
SaBCT|aBC;
TABCT|ABC
BAAB
CAAC
CBBC
aAaa
aBab
bCbc
In this grammar LHS is not Longer than RHS. That means LHS<=RHS.
The Language L={anbncn|n>0} is a Context sensitive language.
Linear Bound Automata
Context sensitive grammars are recognize using Linear Bound Automata (LBA). Here
input tape restricted in size. A linear function is used for restricting the length of the
input tape.
Many compiler Languages lies between Context sensitive and context free languages.
A linear bound automation is a non deterministic Turing machine which has a single
tape whose length is not infinite but bounded by a linear function.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Formal definition
M={Q, , Γ, δ, q0, #, <, >, F}
where
Q is a set of states
 is a set of input symbol.
Γ is a set of tape symbol including Blank space #.
δ is a set of Transition function
δ ( Q x Γ ) = ( Q x Γ x { L, R, N } )
q0 is initial state
# is blank symbol
< is a left end marker in the input tape.
> is a right end marker in the input tape.
F is a final state.
When on input string processed using an LBA. Input string enclosed between < and >
end markers. The end marker < prevents the R head from getting off from the left end of
the tape. The right end marker > prevents the R head from getting off from the right end
of the tape. On the input tape head does not write. Also On the input tape head does not
move on the left. All the computation is to be done between < and >. On the working
tape head can read and write without any restriction. The LBA is same as Turing
machine except head can move only between end markers.

Time Complexity of Turing Machine


A Turing Machine take a string w, it gives the output in the form of yes or no. here it is
possible to exactly measure the number of moves made by the head of the TM during the
processing of the string. Although the number of moves made by the TM to process the
string depend on the specific string. It is possible to make an estimate of the maximum
possible number of moves that TM will make to accept or reject a string of length of n.
Time Complexity of a TM, M is written as, TM(n) where T is the time complexity, n is a
natural number. Time Complexity of a TM is the maximum number of moves made by
the head to accept or reject a string of length n in the worst case scenario.
Example 1:
Consider the TM to accept the language
L={wwR|w(a,b)+}
Find the time complexity of the TM
Let the string of the length n
Here TM works as follows:
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
It checks the first symbol of the input string, converts to it #, and travels the whole of
the string and reaches the # just following the string. It turns back and matches the last
symbol of the string with the first one. If the match occurs, the last symbol is replaced
with #. Next the head travels back to the second symbol of the input string. Here the
number of moves required is 2n+1. On reaching the second symbol. It finds its
corresponding match Here the number of moves required is 2n-3. When all pairs are
successfully matched. TM just makes one move and halts. The worst case is one in
which the input string is valid and the TM has to match all the corresponding pairs.
Also, with every match, number of moves required to match the next symbol decreases.
The process stops when all the symbols are successfully matched and move is required.
Now the TM halts. Total number of moves made by the TM is,
(2n+1) + (2n-3) + (2n-7)+…….+1
=((2n+1) + 1) /2 * (n/2+1)
=(n+1)*(n/2+1)
=n2/2+3n/2+1
Thus the time complexity of TM is O(n2)
T (n) = O(n2)

Halting Problem of TM
Here we use a process called reduction. Let A is the problem of finding some root of x 4 -
3x2 + 2 = 0 and B is the problem of finding some root of x 2 – 2 = 0. Here x2 – 2 is a factor
of x4 - 3x2 + 2 = 0.
Then we can say that A is reducible to B. Thus a problem A is reducible to problem B if
a solution to problem B can be used to solve problem A.
Then if A is reducible to B and B is decidable, then A is decidable. If A is reducible to B
and B is un decidable, then A is un decidable.

Halting Problem of TM
This problem states that halting problem of a Turing Machine is un decidable.
Proof:
To show this, we reduce problem of halting to a problem of acceptance. Consider the
following TM.

Here we take an instance (M,w) and construct another instance (M1,w1). It is taken such
that M1 halts on input w1, iff M accept w. the machine M1 stops when M1 halts.
Initially, the string w is fed to the TM, M and w1 is fed to the TM, M1.
If M accepts w, then it sends a halt signal to M 1. Then TM, M1 halts on input w1. if M
rejects w, then M1 does not halt on w1.
Thus halting of M1 depends on the acceptance behavior of M. Acceptance behavior of
the TM is un decidable, halting of M1 of M1 is un decidable.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Recursive Language.
A Language, L is recursive. If it is possible to design a TM that halts in the final state to
say yes if wL, and halts in the non final state to say no if w  L.

Recursively Enumerable Language


A Language, L is recursively enumerable.0 If it is possible to design a TM that halts in
the final state to say yes if wL, and halting cannot be guaranteed. if w  L.

Language that are neither Recursive nor Recursively Enumerable


A Language, L is neither recursive nor recursively enumerable, if the structure of the
language is such that no TM which recognizes w can be designed.

Rice Theorem
Rice’s Theorem states that
Every nontrivial property of a recursively enumerable language is un decidable.
Proof:
A nontrivial property is one that is possessed by some objects of a class, but no all. For
example, being a mathematician is a property that is possessed by some humans but
not to all. Some cats are black not for all. Some black colour property cannot be trivially
associated with cats.
Let x be a nontrivial property that is not possessed by all recursively enumerable
language. This problem can be reduce to one consisting of a pair (M,w) such that L
possesses x iff w  L(w). we take UTM U that takes a pair (M,w); it is output is yes iff x is
possessed by L.
Since L is recursively enumerable language, there must be a TM, M L that accepts L. Let
x be a string belonging to L. Now, we design a machine M1 to decide x as shown below.

Here U is a UTM. UTM U takes the pairs (M,w) and checks if w  L(M). If the output is
yes, then the machine ML that accepts the string x starts and the output of the machine
M1 is yes. Thus the decidability of the problem of possessing the trivial property reduces
to the problem of Lu. If the pair (M,w)  Lu, then L possesses x; otherwise not. Since Lu is
not recursive, possession of x by L is also not decidable.

Decidable Language:
A language is called Decidable or Recursive if there is a Turing machine which accepts
and halts on every input string w. Every decidable language is Turing-Acceptable.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
A decision problem P is decidable if the language L of all yes instances to P is decidable.
For a decidable language, for each input string, the TM halts either at the accept or the
reject state as depicted in the following diagram

Example 1:
Find out whether the following problem is decidable or not: Is a number ‘m’ prime?
Solution
Prime numbers = {2, 3, 5, 7, 11, 13, …………..}
Divide the number ‘m’ by all the numbers between ‘2’ and ‘√m’ starting from ‘2’. If any of
these numbers produce a remainder zero, then it goes to the “Rejected state”, otherwise
it goes to the “Accepted state”. So, here the answer could be made by ‘Yes’ or ‘No’.
Hence, it is a decidable problem.

Example 2:
Given a regular language L and string w, how can we check if w∈ L?
Solution
Take the DFA that accepts L and check if w is accepted

Some more decidable problems are:


1. Does DFA accept the empty language?
2. Is L1∩ L2=Ø for regular sets?
Note:
1. If a language L is decidable, then its complement L' is also decidable.
2. If a language is decidable, then there is an enumerator for it.
The acceptance problem for DFAs of testing whether a particular deterministic finite
automaton accepts a given string can be expressed as a language, ADFA. This language
contains the encodings of all DFAs together with strings that the DFAs accept. Let
ADFA = { < B, w > | B is a DFA that accept s input string w }.
The problem of testing whether a DFA B accepts an input w is the same as the problem
of testing whether a <B,w> is a member of the language ADFA. Similarly we can formulate
other computational problem in terms of testing membership in a language.
In the following theorem we show that ADFA is decidable. Hence this theorem shows that
the problem of testing whether a given finite automaton accepts a given string is
decidable.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Theorem 1.
ADFA is decidable language.

Proof Idea: we simply need to present a TM M that decides ADFA.


M= “ On input <B,w>, where B is DFA and w is a string.
1. Simulate B on input w.
2. If the simulation ends in an accept state, accept. If it ends in a non accepting
state, reject.”
Let’s examine the input <B,w>. it is a representation of a DFA B together with a string w.
one reasonable representation of B is simply a list of its five components, Q,,δ,q0 and F.
when M receives its input, M first determines whether it properly represents a DFA B
and a string w. if not, M rejects.
Then M carries out the simulation directly. It keeps track of B’s current state and B’s
current position in the input w by writing this information on the tape. Initially, B’s
current state is q0 and B’s current input position is the leftmost symbol of w. The states
and position are updated according to the specified transition function δ. When M
finishes the last symbol of w, M accepts the input if B is in an accepting state; M reject
the input if B is in a non accepting state.
We can prove similar theorem for nondeterministic finite automata. Let
ANFA = { < B, w > | B is a NFA that accept s input string w }.

Theorem 2.
ANFA is decidable language.
PROOF: we present a TM N that decides ANFA. We could design N to operate like M,
simulating an NFA instead of a DFA. Instead, we will do it differently to illustrate a new
idea have N use M as a subroutine. Because M is designed to work with DFA. N first
converts the NFA it receives as input to a DFA before passing it to M.
N= “On input <B,w> where B is a NFA and w is a string
1. Convert NFA B to an equivalent DFA C by using the procedure for this
conversion.
2. Run TM M from Theorem 1 on input <C,w>.
3. If M is accepts, then string w is accepted. Otherwise rejected”.
Similarly, we can determine whether a regular expression generates a given string.
Let AREX = {<R,w> R is a regular expression that generates string w}.

Theorem 3.
AREX is decidable language.
PROOF: The following TM P decides AREX.
P=”On input <R,w> where R is a regular expression and w is a string.
1. Convert regular expression R to equivalent NFA A by using the procedure for this
conversion.
2. Run TM N on input <A,w>.
3. If N is accepts, then string w is accepted. Otherwise rejected”.
Theorem 1, 2 and 3 illustrate that, for decidability purposes, presenting the Turing
machine with DFA, NFA, or regular expression are all equivalent because the machine is
able to convert one form to another.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Now we turn to a different kind of problem concerning finite automata: emptiness testing
for the language of a finite automaton. In the preceding three theorems we had to
determine whether a finite automaton accepts a particular string. In the next proof we
must determine whether a finite automaton accepts any string at all.
Let EDFA = {<A>| A is a DFA and L(A)=Ø}.

Theorem 4.
EDFA is decidable language.
PROOF: A DFA accepts some string iff reaching an accepts state from the start state by
travelling along the arrows of a DFA is possible. To Test is condition we design a TM T
that uses a marking algorithm.
T=”On input <A> where A is a DFA.
1. Mark the start state of A.
2. Repeat until no new states get marked.
3. Mark any state that has a transition coming into it from any state that is already
marked.
4. If no accept state is marked, accept; otherwise reject”.
The next theorem states that determining whether two DFAs recognize the same
language is decidable. Let

Theorem 5.
EQDFA = {<A,B>| A and B are DFAs and L(A) = L(B)}.
PROOF: we convert a new DFA C from A and B, Where C accepts only those strings that
are accepted by either a or B not by both. Thus, A and B recognize the same language, C
will accept nothing. The language of C is

This expression is some time called the symmetric different of L(A) and L(B) and
illustrate in the following figure. Here L(A)1 is the complement of L(A). The symmetric
different is useful here because L(C)=Ø iff L(A)=L(B).
We constructed C from the theorem 4 to test whether L(C) is empty. If it is empty, L(A)
and L(B) must be equal.
F=”On input <A,B>, where A and B are DFAs.
1. Construct DFA C as described.
2. Rum TM T from Theorem 4 on input <C>.
3. If T is accepts, accept. If T rejects, reject.”

FIGURE 6: The symmetric different of L(A) and L(B).

DECIDABLE PROBLEMS CONCERNING CFL


Here, we describe algorithms to determine whether a CFG generates a particular string
and to determine whether the language of a CFG is empty. Let
ACFG = {<G,w>| G is a CFG that generates string w}.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Theorem 7:
ACFG is a decidable language.
PROOF IDEA: For CFG G and string w, we want to determine whether G generates w.
One idea is to use G to go through all derivations to determine whether any is a
derivation of w. This idea doesn’t work, as infinitely many derivations may have to be
tried. If G does not generate w, this algorithm would never halt. This idea gives a Turing
machine that is a recognizer, but not a decider, for ACFG.
PROOF The TM S for ACFG follows.
S = “On input <G,w>, where G is a CFG and w is a string:
1. Convert G to an equivalent grammar in Chomsky normal form.
2. List all derivations with 2n−1 steps, where n is the length of w; except if n = 0,
then instead list all derivations with one step.
3. If any of these derivations generate w, accept ; if not, reject .”
Let’s turn now to the emptiness testing problem for the language of a CFG. As we did for
DFAs, we can show that the problem of determining whether a CFG generates any
strings at all is decidable. Let ECFG = {<G>| G is a CFG and L(G) = Ø}.

Theorem 8:
ECFG is a decidable language.
PROOF IDEA To find an algorithm for this problem, we might attempt to use TM S from
Theorem 7. It states that we can test whether a CFG generates some particular string w.
To determine whether L(G) =Ø, the algorithm might try going through all possible w’s,
one by one. But there are infinitely many w’s to try, so this method could end up
running forever. We need to take a different approach.
In order to determine whether the language of a grammar is empty, we need to test
whether the start variable can generate a string of terminals. The algorithm does so by
solving a more general problem. It determines for each variable whether that variable is
capable of generating a string of terminals. When the algorithm has determined that a
variable can generate some string of terminals, the algorithm keeps track of this
information by placing a mark on that variable.
First, the algorithm marks all the terminal symbols in the grammar. Then, it scans all
the rules of the grammar. If it ever finds a rule that permits some variable to be replaced
by some string of symbols, all of which are already marked, the algorithm knows that
this variable can be marked, too. The algorithm continues in this way until it cannot
mark any additional variables. The TM R implements this algorithm.
PROOF
R = “On input <G>, where G is a CFG:
1. Mark all terminal symbols in G.
2. Repeat until no new variables get marked:
3. Mark any variable A where G has a rule A U1U2 · · ·Uk and each symbol U1, . . .
,Uk has already been marked.
4. If the start variable is not marked, accept ; otherwise, reject .”
Next, we consider the problem of determining whether two context-free grammars
generate the same language. Let
EQCFG = {<G,H>| G and H are CFGs and L(G) = L(H)}.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Theorem 5 gave an algorithm that decides the analogous language EQ DFA for finite
automata. We used the decision procedure for EDFA to prove that EQDFA is decidable.
Because ECFG also is decidable, you might think that we can use a similar strategy to
prove that EQCFG is decidable. But something is wrong with this idea! The class of
context-free languages is not closed under complementation or intersection EQCFG is not
decidable. Now we show that context-free languages are decidable by Turing machines.

Theorem 9:
Every context-free language is decidable.
PROOF IDEA Let A be a CFL. Our objective is to show that A is decidable. One (bad) idea
is to convert a PDA for A directly into a TM. That isn’t hard to do because simulating a
stack with the TM’s more versatile tape is easy. The PDA for A may be nondeterministic,
but that seems okay because we can convert it into a nondeterministic TM and we know
that any nondeterministic TM can be converted into an equivalent deterministic TM. Yet,
there is a difficulty. Some branches of the PDA’s computation may go on forever, reading
and writing the stack without ever halting. The simulating TM then would also have
some non halting branches in its computation, and so the TM would not be a decider. A
different idea is necessary. Instead, we prove this theorem with the TM S that we
designed in Theorem 7 to decide ACFG.
PROOF Let G be a CFG for A and design a TM MG that decides A. We build a copy of G
into MG. It works as follows.
MG = “On input w:
1. Run TM S on input <G,w>.
2. If this machine accepts, accept ; if it rejects, reject .”

Complexity
In this module, we will learn different complexity classes, such as P and NP.
In data structures, we already learned about time complexity and space complexity.
Here we will be concerned about time complexity of various problems. We learned
computable and non computable functions.
 A computable function is a function for which we can construct a Turing machine.
Or an algorithm can be formulated.
 A non computable function is one in which no Turing machine can be constructed.
Here we cannot devise an algorithm.
Tractable and intractable Problems Consider computable functions. These functions are
computable or solvable. We can construct a TM for them. We can devise an algorithm for
them. But many of these problems can be solved only in principle, not in practice. This
is because some of the computable functions may take 1000s of years to find a solution
using a computer system. Such problems are termed intractable problems. They come
under complexity class NP. Most of the problems we are familiar with can be solved
within a reasonable amount of time. Such problems are said to be tractable. They come
under complexity class P.

Complexity Class P
Consider some of the problems we learned in data structures, such as bubble sort,
quick sort, merge sort, binary search, matrix multiplication etc..
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Also we learned that,
The time complexity of bubble sort is Ø(n2).
The time complexity of quick sort is Ø(n log n).
The time complexity of merge sort is Ø(n log n).
The time complexity of heap sort is Ø(n log n).
The time complexity of binary search is Ø(log n).
The time complexity of matrix multiplication algorithm is Ø(n3).

Consider time complexity values of all these algorithms. They are of the order of n2, n
log n, log n, n3 etc..
If we calculate exact value, we get polynomials such as 5n2 + 2n + 4, n log n + 5n + 9,
7n3 +3n2 + 9n+ 3 etc.. They are polynomials. This means that above algorithms are
polynomial time algorithms. These polynomial time algorithms can be solved within a
reasonable amount of time.
This means these problems can be solved in practice. Consider the problem, sorting
using bubble sort. The time complexity of bubble sort is Ø(n2). This means if there are
10 numbers in the list, a machine will take Ø(102) time to sort. If there are 100 numbers
in the list, a machine will take Ø(1002) time to sort. If there are 1000 numbers in the
list, a machine will take Ø(10002) time to sort.
All these time values are reasonable. A computing machine can solve this sorting
problem within a small amount of time. Almost all the algorithms we learned have time
complexity values n3, n2, n log n, n, log n, etc.. . That is, for most of these algorithms,
the exponent of n is at most 3.
These problems can be solved within a reasonable amount of time by a computing
machine or a TM. These problems come in complexity class P. But if an algorithm for a
problem has time complexity Ø(n1000), it is not a reasonable amount of time.
This is also a polynomial time. But for such a problem, it has observed that somebody
will invent a new algorithm that has time complexity of the order of a small value of
exponent such as n4 or n3.

Complexity Class P
The class P consists of those problems that are solvable in polynomial time. This means
these problems can be solved in time Ø(nk), where n is the size of the input, k is a
constant.
Another definition is, A problem is in class P, if there exists a deterministic Turing
Machine of polynomial time complexity. Examples for problems in class P are sorting
using bubble sort, quick sort, heap sort etc.. ; searching using binary search, sequential
search, ; matrix multiplication algorithm etc.. Most of the problems we are familiar with
come under class P.

P - Hard Problems:
A problem A, is said to be P-hard if, every P problem can be reduced to A.

P - Complete Problems: A problem A, is said to be P-complete if, A is P, and A is P-


hard.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Examples for P-complete problems : Emptiness problem for context free grammars.
 Circuit Value Problem (CVP) — Given a circuit, the inputs to the circuit, and one gate
in the circuit, calculate the output of that gate.
 Linear programming - Maximize a linear function subject to linear inequality
constraints
 Lexicographically First Depth First Search Ordering - Given a graph with fixed
ordered adjacency lists, and nodes u and v, is vertex u visited before vertex v in a
depth—first search induced by the order of the adjacency lists? Context Free
Grammar Membership - Given a context—free grammar and a string, can that string
be generated by that grammar?
 Horn—satisfiability: given a set of Horn clauses, is there a variable assignment which
satisfies them? This is P’s version of the boolean satisfiability problem.
 LZW Data Compression — given strings s and t, will compressing s with an LZ78
method add t to the dictionary? (Note that for LZ77 compression such as gzip, this is
much easier, as the problem reduces to "|s t in s?".)

Emptiness Problem for Context Free Grammars:


The emptiness problem is whether the grammar generates any terminal strings at all.
Emptiness Problem for CFGs is P-Complete.

Theorem: The emptiness problem for context - free grammars is P-complete.


Proof: Consider any context—free grammar G ={V, Z, P, S}. The emptiness of L(G) can be
determined by the following algorithm.
Step 1: Prove that the problem is P.
Mark each of the terminal symbols in ∑. Search P for a production A α, in which a
consists only of marked symbols and A is unmarked. If such a production rule A α
exists, then mark A and repeat the process. If the start symbol S is unmarked, then
declare L(G) to be empty. Otherwise, declare L(G) to be nonempty. The number of
iterations of Step 2 is bounded above by the number of non terminal symbols in N.
Consequently, the algorithm requires polynomial time and the problem is in P.
Step 2: Prove that the problem is P-hard To show that the emptiness problem for
context - free grammars is P-hard, consider any problem K in P. [This part of the proof is
beyond the scope of this class.]

Complexity Class NP Complexity class NP consists of following types of problems: NP


problems, NP-hard problems, NP-complete problems.
Consider computable functions. For these functions, a TM exists or they are solvable.
But some of the computable functions can be solved only in principle, not in practice.
This is because a computing machine may take 1000s of years to solve such problems.
For these problems, a polynomial time algorithm has not yet been invented. We may
wish somebody will invent a polynomial time algorithm for these problems in the future.
For these problems, time complexity is found to be Ø(2n). This is not polynomial time, it
is super polynomial time complexity.
When the value of n is 10, time complexity value of such a problem will be Ø(210), which
is a manageable number. When the value of n is 100, time complexity value of such a
problem will be Ø(2100).
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
This value is greater than the number of molecules in the universe. This means, such
problems cannot be solved by a computer in practice (when n is large). They are solvable
in principle only. These problems come under complexity class NP.
Some examples for such problems in NP are,
 Circuit satisfiability problem,
 Boolean Formula satisfiability problem (SAT),
 3-CNF satisfiability problem,
 Clique problem,
 Vertex cover problem,
 Hamiltonian cycle problem,
 Traveling salesman problem (TSP).

Complexity Class NP
The class NP consists of those problems that are “verifiable” using a polynomial time
algorithm. What do you mean by “verifiable”.
This means if somebody gives a ‘certificate’ of solution for such a problem, then we can
verify that the certificate is correct in polynomial time. For example, consider the
Hamiltonian cycle problem,
Let somebody gives us a certificate that a Hamiltonian cycle, A-
C-B-D-F-E-A exists in the above graph, it can be verified very
easily in polynomial time. But if we are asked to find a
Hamiltonian cycle from the above graph, it cannot be solved in
polynomial time.
Another definition is, A problem is in class NP if there exists a non-deterministic Turing
machine of polynomial time complexity. All problems in P are also in NP. This is because
all problems in P are verifiable in polynomial time. That is, P  NP.

Polynomial Time Reducibility In some cases, a problem can be reduced to another


problem. Consider the problem of solving the linear equation, bx + c = 0. We may
transform this to the quadratic equation 0x2 + bx + c = 0. Solution of this quadratic
equation is same as the solution of the given linear equation. A problem A is reducible to
another problem B, if it is possible to convert every instance of A to a corrsponding
instance of B. If this reduction is possible in polynomial time, then we say that A is
polynomial time reducible to B. This is denoted as, A P B.
This means A can be reduced to B in polynomial time. If the algorithm used for
reduction is f, then if an x  A, iff f(x)  B, and x  A, iff f(x)  B.
This is shown below:

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
From the above figure, x1  A,
f(x1) = y1,
y1  B.
also x 3  A,
f(x3)=y3,
y3  B.

NP - Hard Problems: A problem A, is said to be NP-hard if, every NP problem can be


reduced to A in polynomial time.
Let A be a problem. We say that A is NP-hard, if L P A , for every L  NP.

NP - Complete Problems: A problem A, is said to be NP-complete if, A is NP, and A is


NP-hard.
Thus if we want to prove that a problem is NP complete, we need to prove that it is NP,
and all NP problems can be reduced to this problem (NP-hard). Examples for NP
complete problems are,
 Circuit satisfiability problem,
 Boolean Formula satisfiability problem (SAT),
 3—CNF satisfiability problem,
 Clique problem,
 Vertex cover problem,
 Hamiltonian cycle problem,
 Traveling salesman problem (TSP).

Proving that a problem is NP complete


We will prove that above problems are NP complete. The approach we use is as follows:
We will prove that Boolean Formula satisfiability problem (SAT) is NP complete. This is
done by proving that SAT is NP, and All problems in NP are reduced to SAT.

To prove that 3-CNF-SAT is NP complete:


Prove that 3-CNF-SAT is NP. SAT is reduced to 3-CNF-SAT. [All NP problems can be
reduced to SAT. SAT can be reduced to 3-CNF-SAT. This means all NP problems can be
reduced to 3-CNF-SAT.] This means 3-CNF-SAT is NP hard.

To prove that Clique problem is NP complete:


Prove that Clicque problem is NP. 3-CNF-SAT is reduced to Clique problem. [All NP
problems can be reduced to SAT. SAT can be reduced to 3-CNF- SAT. 3-CNF-SAT can be
reduced to Clique problem. This means all NP problems can be reduced to Clique
problem.] This means Clique problem is NP hard.

To prove that vertex cover problem is NP complete:


Prove that vertex cover problem is NP. Clique problem is reduced to vertex cover
problem. [All NP problems can be reduced to SAT. SAT can be reduced to 3-CNF-SAT. 3-
CNF-SAT can be reduced to Clique problem. Clique problem can be reduced to vertex
cover problem. This means all NP problems can be reduced to vertex cover prob|em.]
This means vertex cover problem is NP hard.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
To prove that Hamiltonian cycle problem is NP complete:
Prove that Hamiltonian cycle problem is NP. Vertex cover problem is reduced to
Hamiltonian cycle problem. [All NP problems can be reduced to SAT. SAT can be
reduced to 3-CNF-SAT. 3-CNF-SAT can be reduced to Clique problem. Clique problem
can be reduced to vertex cover problem. Vertex cover problem can be reduced to
Hamiltonian cycle problem. This means all NP problems can be reduced to Hamiltonian
cycle problem. This means Hamiltonian cycle problem is NP hard.

To prove that Traveling Salesman(TSP) problem is


NP complete:
Prove that TSP is NP. Hamiltonian cycle problem is
reduced to TSP [All NP problems can be reduced to
SAT. SAT can be reduced to 3-CNF-SAT. 3-CNF-SAT
can be reduced to Clique problem. Clique problem can
be reduced to vertex cover problem. Vertex cover
problem can be reduced to Hamiltonian cycle problem.
Hamiltonian cycle problem can be reduced to TSP. This
means all NP problems can be reduced to TSP.] This
means TSP is NP hard.
Thus approach we use for proving a problem is NP-
complete is shown below.

SAT (Boolean Formula Satisfiability Problem)


An example for a Boolean formula is
(x1  x2 )  ( x1  x2 )  (x2  x3 )  (x1  x2  x3 )
This formula is in conjunctive normal form (CNF) (intersection of unions). This boolean
formula is satisfiable if there is some assignment of the values 0 and 1 to its variables
that causes it to evaluate to 1 (true).
If we put, x1 = 0, x2 = 0, x3 = 1, we can see that the above formula evaluates to 1 (true).
This means above formula is satisfiable. Consider the boolean formula,
( x1  x2 )  ( x1  x2 )
If we put x1 = 0, x2 = 0, this formula evaluates to 0. If we put x1 = 0, x2 = 1, this
formula evaluates to 0. If we put x1 = 1, x2 = 0, this formula evaluates to 0. If we put x1
= 1, x2 = 1, this formula evaluates to 0. This means for any values assigned to the
variables the above Boolean formula always evaluate to 0 (false). This means the formula
is not satisfiable.
SAT Problem: SAT (Boolean Formula Satisfiability) problem is defined as: Is there a set
of values for the Boolean variables that assigns the value 1 (true) to the boolean
expression given in CNF?
Cook’s Theorem:
Cook’s theorem states that satisfiability of Boolean formulas (SAT problem) is NP-
Complete. SAT Problem is NP - Complete We know that a problem is in class NP-
Comp|ete if: it is in NP and it is NP Hard. Theorem: Satisfiability of boolean formulas is
NP-Complete.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Proof:
Step 1: Prove that SAT problem is in class NP.
A Boolean variable can have two possible values. Hence, for an n variable Boolean
expression in CNF, there are 2n possible combinations of values of these variables. If we
want to check whether a Boolean formula is satisfiable, we need to apply each
combination to the formula until we get a 1 as the result of evaluation. In the worst
case, we need to apply all the 2n possible combinations. Consider the formula, (x1x2
)(x1 x2)(x2x3)(x1x2x3) There are 3 variables. Each variable can have
two possible values, 0 or 1. There are 23 combinations. So the time complexity of this
problem is Ø(2n). (not polynomial time) If we are given a certificate containing a
satisfiable assignment for a formula, then we can easily verify it in polynomial time.
For example, for the above formula, if we are given a certificate saying that if x1 = 0, x2 =
0, x3 = 1, then just applying these values to the formula, we get,
(x1x2 )(x1 x2)(x2x3)(x1x2x3)
=(00 )(0 0)(01)(001)
=(10 )(0 1)(11)(111)
=1111 = 1
This can be done in linear time. So the SAT problem is in class NP.
Step 2: Prove that SAT problem is NP-hard. We know that a problem is NP-Hard, if every
problem in NP can be reduced to this problem in polynomial time.

3-CNF Satisfiability Problem (3-CNF-SAT)


We know that a Boolean formula is in conjunctive normal form(CNF) if it is expressed as
an AND of clauses, each clause is the OR of one or more variables.
Then, a formula is in 3-conjunctive normal form (3-CNF) is each clause has exactly three
distinct literals. For example, the following Boolean formula is in 3-CNF.
(x1x1x2)( x3x2x4)(x1x3x4)(x2x1x3)
The clauses in the above formula contain exactly 3 literals. The formula is in 3-CNF.

3-CNF Satisfiability Problem


3-CNF-SAT problem is defined as: Is there a set of values for the Boolean variables that
assigns the value 1 (true) to the Boolean expression given in 3-CNF?

3-CNF Satisfiability Problem is NP-complete We know that a problem is in class NP-


Complete if: it is in NP and it is NP Hard. Theorem: Satisfiability of boolean formulas in
3-CNF is NP-complete.

Proof:
Step 1: Prove that 3-CNF-SAT is in class NP. A boolean variable can have two possible
values. Hence, for an n variable boolean expression in CNF, there are 2n possible
combinations of values of these variables. If we want to check whether a boolean
formula is satisfiable, we need to apply each combination to the formula until we get a 1
as the result of evaluation. In the worst case, we need to apply all the 2n possible
combinations. Consider the formula,
(x1x1x2)( x3x2x4)(x1x3x4)(x2x1x3)

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
There are 4 variables. Each variable can have two possible values, 0 or 1. There are 24
combinations. So the time complexity of this problem is Ø(2n). (not polynomial time) If
we are given a certificate containing a satisfiable assignment for a formula, then we can
easily verify it in polynomial time.
For example, for the above formula, if we are given a certificate saying that if x1 = 0, x2 =
1, x3 = 0, x4 = 1, then just applying these values to the formula, we get,
(x1x1x2)( x3x2x4)(x1x3x4)(x2x1x3)
=(001)( 011)(001)(100)
=(010)( 011)(110)(101)
=1111=1
This can be done in linear time. So the 3-CNF-SAT problem is in class NP.
Step 2: Prove that 3-CNF-SAT problem is NP-hard. We know that a
problem is NP-Hard, if every problem in NP can be reduced to this
problem in polynomial time. The approach we used is as follows: In the
previous section, we already proved that all NP problems can be reduced
to SAT. Then, if we can reduce SAT to 3-CNF-SAT in polynomial time, we
can say that 3-CNF-SAT is NP-hard.
We learned in the subject, ’logic design’ that any boolean formula can be expressed in
CNF. Then, a boolean formula in CNF can be rewritten in 3-CNF.
Consider a boolean formula as follows: aUbUcUd This can be converted to 3-CNF as,
(aUbUx) (cUdUx) Thus any boolean formula can be transformed to a 3-CNF boolean
formula. This can be done using De Morgan’s laws. That means SAT problem can be
reduced to 3-CNF-SAT problem. That is, 3-CNF-SAT is NP-hard.
In step 1, we proved that 3-CNF-SAT is in NP.
In step 2, we proved that 3-CNF-SAT is NP-hard.
So, 3-CNF-SAT is an NP-complete problem.

Clique Problem
Clique
Let we are given a graph with a number of vertices. A clique is a subset of vertices, such
that an edge is present between every pair of vertices. Consider the following graph:

In the beside graph, a clique is {u,v,x,y}. The size of this


clique is 4.
A clique is a sub graph of the above graph which is shown
below:

The above set is a clique, because uv, ux, uy, vx, vy, xy are edges in
the given graph. Clique problem is to check whether a clique of size k
is present in the graph.
Clique Problem is NP-Complete We know that a problem is in class
NP-Complete if: it is in NP and it is NP Hard.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Theorem: Clique problem is NP-complete.
Proof:
Step 1: Prove that clique problem is in class NP.
A set with n elements has 2n possible subsets. Then a graph with n vertices has 2n
possible sub graphs. So an algorithm needs to check whether any one of these sub
graphs form a clique. It has worst case time complexity Ø(2n). (non polynomial time, but
exponential time).
Let we are given a graph and a ’certificate’ telling that a subset of vertices form a clique.
An algorithm can verify this in polynomial time.
So clique problem is in class NP.
Step 2: Prove that clique problem is NP-hard.
We know that a problem is NP-Hard, if every problem in NP can be
reduced to this problem in polynomial time. The approach we used is
as follows: In the previous section, we already proved that all NP
problems can be reduced to SAT. Then, again we found that SAT
problem can be reduced to 3-CNF-SAT problem. Then, if we can reduce
3-CNF-SAT problem to clique problem in polynomial time, we can say
that clique is NP-hard.
We need to reduce 3-CNF-SAT problem to clique problem. Consider a 3-CNF boolean
formula given below:
(aUbUc) (aUbUc) (aUbUc) A graph is produced from the above formula as:

The graph is produced as follows: Every vertex in a clause is connected to every other
vertex in another clause. But a vertex x should not be connected to vertex x.
This graph corresponding to 3-CNF-SAT has a solution if the corresponding vertices
form a clique. In the above graph, vertices b of C1, a of C2 , c of C3 form a clique.

In the above clique, C1 has the vertex b. So put b=0. C2 has the vertex a. So put a=0.
C3 has the vertex c. So put c=1.
Thus a satisfying assignment to the given boolean formula is a=0, b=0, c=1. Consider
the given boolean formula,
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
=(aUbUc) (aUbUc) (aUbUc) put a=0, b=0, c=1. We get
=(0U0U1) (0U0U1) (0U0U1)
=(0U1U0) (1U0U1) (0U0U1)
=1 1 1=1
Thus the given formula in 3-CNF gives true for a=0, b=0, c=1.
Thus the given 3-CNF-SAT problem is reduced to clique problem. This means clique
problem is NP-hard.
In step 1, we proved that clique is in NP.
In step 2, we proved that clique is NP-hard.
So, clique is an NP-complete problem.

Vertex Cover Problem


Vertex Cover
A vertex cover of a graph is a set of vertices, V such that if (a, b) is an edge of a graph,
then a or b or both must be present in V.
Consider the following graph:

In the above graph, vertex cover is {z, w}.


Let V={z, w}
The edges of the above graph are uw, vw, xw, vz, yz. Note that in every edge, at least one
vertex is a member of V.
For example,
Consider the edge uw. Here, vertex w  V.
Consider the edge vz. Here, vertex z  V.
Thus, {z, w} form a vertex cover.

Vertex Cover Problem


The vertex cover problem is to check whether a graph has a vertex cover of size k. Vertex
Cover Problem is NP-Complete We know that a problem is in class NP—Complete if: it is
in NP and it is NP Hard.
Theorem: Vertex cover problem is NP-complete.
Proof:
Step 1: Prove that vertex cover problem is in class NP.
A set with n elements has 2" possible subsets. Then a graph with n vertices has 2"
possible subsets of vertices.
So an algorithm needs to check whether any one of these subsets form a vertex cover. It
has worst case time complexity Ø(2n). (not polynomial time, but exponential time).
Let we are given a graph and a ’certificate’ telling that a subset of vertices form a vertex
cover. An algorithm can verify whether at leat one vertex of every edge in the graph is an
element of this vertex cover in polynomial time. So vertex cover problem is in class NP.
Step 2: Prove that vertex cover problem is NP-hard.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
We know that a problem is NP-Hard, if every problem in NP can be reduced to this
problem in polynomial time.
The approach we used is as follows: In the previous section, we already
proved that all NP problems can be reduced to SAT. Then, again we
found that SAT problem can be reduced to 3-CNF-SAT problem. Again,
we reduced 3-CNF-SAT problem to clique problem. Then, if we can
reduce clique problem to vertex cover problem in polynomial time, we
can say that vertex cover problem is NP-hard.
We need to reduce clique problem to vertex cover problem.
Consider the following graph with clique {u, v, x, y}.

For the graph G1, vertex cover is {z,w}.


This vertex cover is found by V-V’. That is, {u,v,w,x,y,z}-{u,v,x,y}
= {z,w}
So from the clique, we can find out the vertex cover of a graph
using the above mechanism. Thus the given clique problem is
reduced to vertex cover problem. This means vertex cover
problem is NP-hard.
In step 1, we proved that vertex cover problem is in NP.
In step 2, we proved that vertex cover problem is NP-hard.
So, vertex cover problem is an NP-complete problem.

Hamiltonian Cycle Problem


Hamiltonian Cycle
A hamiltonian cycle in an undirected graph is a simple cycle which contains every vertex
of the graph.
A graph which contains a hamiltonian cycle is called hamiltonian. A graph which does
not contain a hamiltonian cycle is called nonhamiltonian.
Example: Consider the following graph:

Note that the Hamiltonian cycle path passes through every vertex.
Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Hamiltonian Cycle Problem
The Hamiltonian cycle problem is to check whether a graph has a Hamiltonian cycle..
Hamiltonian Cycle Problem is NP-Complete.
We know that a problem is in class NP-Complete if: it is in NP and it is NP Hard.
Theorem: Hamiltonian cycle problem is NP-complete.
Proof:
Step 1: Prove that Hamiltonian cycle problem is in class NP.
A set with n elements has 2n possible subsets. Then a graph with n vertices has 2n
possible permutations of vertices.
So an algorithm needs to check whether any one of these permutation form a
Hamiltonian path. If the graph is represented as an adjacency matrix, it will take n!
comparisons. It has worst case time complexity Ø(2√n). (not polynomial time, but
exponential time).
Let we are given a graph and a ’certificate’ telling that a sequence of vertices form a
Hamiltonian cycle. An algorithm can verify whether this path is Hamiltonian in
polynomial time. So Hamiltonian cycle problem is in class NP.
Step 2: Prove that Hamiltonian cycle problem is NP-hard.
We know that a problem is NP-Hard, if every problem in NP can be
reduced to this problem in polynomial time. The approach we used is
as follows:
In the previous section, we already proved that all NP problems can
be reduced to SAT. Then, again we found that SAT problem can be
reduced to 3-CNF-SAT problem. Again, we reduced 3-CNF-SAT
problem to clique problem. again, we reduced clique problem to
vertex cover problem. Then, if we can reduce vertex cover problem to
Hamiltonian cycle problem in polynomial time, we can say that Hamiltonian cycle
problem is NP-hard.

Travelling Salesman Problem (TSP)


Travelling Salesman
A salesman begins his tour from a city. He visits a set of cities and he finishes at the city
he starts from. Each city must be visited exactly once.
A graph of a set of cities is given. A salesman starts from a city. He must visit each city
exactly once and should finish at the city he starts from. The path he follows should be
the shortest one or should have a cost value less than k.
Thus TSP is a special case of Hamiltonian cycle problem where the path cost should be
minimum. Consider the following graph containing cities u, v, w, x. V.

Graph Here the traveling salesman can follow the path x—u—w—v—x which forms the
shortest path with cost 7km.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
TSP is NP-Complete
We know that a problem is in class NP-Complete if: it is in NP and it is NP Hard.
Theorem: TSP is NP-complete.
Proof:
Step 1: Prove that TSP is in class NP.
A set with n elements has 2n possible subsets. Then a graph with n vertices has 2n
possible permutations of vertices.
So an algorithm needs to check whether any one of these permutation form a
Hamiltonian path with cost value less than k. If the graph is represented as an
adjacency matrix, it will take n! comparisons. It has worst case time complexity Ø(2√n)..
(not polynomial time, but exponential time).
Let we are given a graph and a ’certificate’ telling that a sequence of vertices form a
Hamiltonian cycle with cost value less than k. An algorithm can verify whether this cycle
has cost less than k in polynomial time. So TSP is in class NP.
Step 2: Prove that Hamiltonian cycle problem is NP-hard.
We know that a problem is NP-Hard, if every problem in NP can be reduced to this
problem in polynomial time.
The approach we used is as follows:
In the previous section, we already proved that all NP problems can be reduced to SAT.
Then, again we found that SAT problem can be reduced to 3-CNF-SAT problem. Again,
we reduced 3-CNF-SAT problem to clique problem. Again, we reduced clique problem to
vertex cover problem. Again we reduced vertex cover problem to Hamiltonian cycle
problem. Then, if we can reduce Hamiltonian cycle problem to TSP in polynomial time,
we can say that TSP is NP-hard.

We need to reduce Hamiltonian cycle problem to TSP. Consider a graph, D .

Following is an instance of hamiltonian cycle.


Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.
Now form a complete graph from the above istance of Hamiltonian cycle.

Next we assign cost value to every edge of this graph. If the edge is present in
Hamiltonian cycle, assign cost value 0 to it. If it is not, assign cost value 1 to it.

From this, an instance of TSP can be produced from the above graph by traversing
through the edges which have cost value 0.
Thus Hamiltonian cycle problem is reduced to TSP. So TSP is NP-hard.
In step 1, we proved that TSP is in NP.
In step 2, we proved that TSP is NP-hard.
So, TSP is an NP—complete problem.

Saravanan Marimuthu Raja B.Sc.(CS), MCA, M.Phil.(CS),Lecturer, IOT Campus, Ambo University, Ambo, Ethiopia.

You might also like