Professional Documents
Culture Documents
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.
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
(ab,R)
Q1 Q2
(aa,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 # # #
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.
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.
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.
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 wL, and halts in the non final state to say no if w L.
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
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.”
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.
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?".)
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.
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.
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,
(x1x1x2)( x3x2x4)(x1x3x4)(x2x1x3)
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,
(x1x1x2)( x3x2x4)(x1x3x4)(x2x1x3)
=(001)( 011)(001)(100)
=(010)( 011)(110)(101)
=1111=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) (cUdUx) 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:
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:
(aUbUc) (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.
=(aUbUc) (aUbUc) (aUbUc) put a=0, b=0, c=1. We get
=(0U0U1) (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.
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.
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.
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.