Top Banner
Theory of Computation Notes Manas Dutta, Deptt of Applied Sciences, Gauhati University PRIMITIVE RECURSIVE FUNCTIONS A partial function from X to Y is a rule which assigns to every element of X atmost one element of Y. A total function from X to Y is a rule which assigns to every element of X a unique element of Y. Eg. : f given by () fr r is a partial function : g given by () 2 gr r is a total function Def. An m-place partial function is a function f with ( ) m dom f and ( ) ran f . If ( ) a dom f then () fa is said to be undefined. If ( ) m dom f , then f is said to be total. Eg. 2 : f defined by (, 1) *( 1) fnn n n . Then f is a partial function since (0,0), (1,1), (1,2) f f f etc are undefined. Again : f defined by ( , ) fmn m n is partial function since f is not defined when m n . But : g defined by ( , ) gmn m n is a total function. Def. Initial functions. The following functions are called Initial Functions: (1) The constant function : n n k C with 1 2 ( , ,..., ) n k n C z z z k (2) The kth projection function : n n k P with 1 2 ( , ,..., ) n k n k P z z z z for 1 k n (3) The successor function : S with () 1 Sz z Def. Basic operations. The following are rules for obtaining new functions from given functions or existing functions: (1) Substitution: 1 2 # ( , , , ...., ): n f Sub f g g g with 1 2 # 1 2 # ( , , , ...., )( ) ( ), ( ),..., () f f Sub f g g g z f g z g z g z where 1 2 # # # ... # f g g g n .
37

theory of computation notes

Jul 11, 2016

Download

Documents

manasdutta3495

mathematics of the theory of computation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: theory of computation notes

Theory of Computation Notes

Manas Dutta,

Deptt of Applied Sciences, Gauhati University

PRIMITIVE RECURSIVE FUNCTIONS

A partial function from X to Y is a rule which assigns to every element of X atmost one element of Y.

A total function from X to Y is a rule which assigns to every element of X a unique element of Y.

Eg. :f given by ( )f r r is a partial function

:g given by ( ) 2g r r is a total function

Def. An m-place partial function is a function f with ( ) mdom f and ( )ran f . If

( )a dom f then ( )f a is said to be undefined. If ( ) mdom f , then f is said to be total.

Eg. 2:f defined by ( , 1) *( 1)f n n n n . Then f is a partial function since (0,0), (1,1), (1,2)f f f etc are undefined.

Again :f defined by ( , )f m n m n is partial function since f is not defined when m n .

But :g defined by ( , )g m n m n is a total function.

Def. Initial functions.

The following functions are called Initial Functions:

(1) The constant function :n nkC with 1 2( , ,..., )n

k nC z z z k

(2) The kth projection function :n nkP with 1 2( , ,..., )n

k n kP z z z z for 1 k n (3) The successor function :S with ( ) 1S z z

Def. Basic operations.

The following are rules for obtaining new functions from given functions or existing functions:

(1) Substitution: 1 2 #( , , ,...., ) : nfSub f g g g with

1 2 # 1 2 #( , , ,...., )( ) ( ), ( ),..., ( )f fSub f g g g z f g z g z g z where 1 2 ## # ... # fg g g n .

Page 2: theory of computation notes

The substitution is simply the composition of f with 1 2 #, ,..., fg g g . For example, 2

1 2 3( , , , ) :Sub f g g g where 1( , )g x y x y , 2 ( , ) 2g x y x , 3 ( , )g x y xy and ( , , )f x y z x y z . Then

1 2 3 1 2 3 1 2 3( , , , )( , ) ( , , ) 2Sub f g g g x y f g g g g g g x y x xy and

1 2 3( , , , )(1, 2) 1 2 2*1 1*2 7Sub f g g g

(2) Primitive Recursion: # 1( , ) : gR g h where # # 2h g obeying the recursion equations

( , )( ,0) ( )( , )( , 1) , , ( , )( , )

R g h z g zR g h z y h z y R g h z y

Assume # g n . Then # 2h n and

1

1 1

1 1 1

2 arguments

( , ) :( , )( ,..., ,0) ( ,..., )( , )( ,..., , 1) ,..., , , ( ,..., , )

n

n n

n n n

n

R g hR g h x x g x xR g h x x y h x x y R x x y

Here if we allow 0n , then we have

:R with

(0)R k , where k is a fixed natural number

( 1) ( , ( ))R y h y R y

Note: We say that f is obtained from g and h (or in the case 0n , from h alone) by recursion.

(3) Restricted operator or Unbounded Minimisation: Assume that 1( ,..., , )ng x x y is a

function such that for any 1,..., nx x there is at least one y such that 1( ,..., , ) 0ng x x y . We

denote by 1( ,..., , ) 0ny g x x y the least number y such that 1( ,..., , ) 0ng x x y .

Let 1 1( ,..., ) ( ,..., , ) 0n nf x x y g x x y . Then f is said to be obtained from g by means

of the restricted operator if the given assumption about g holds (namely that, for any

1,..., nx x ) there is at least one y such that 1( ,..., , ) 0ng x x y ).

Page 3: theory of computation notes

Def. Primitive Recursive Functions.

A total function f is said to be Primitive Recursive iff it can be obtained from the initial functions by finite number of substitutions and primitive recursion. This means that the three initial functions are primitive recursive.

Def. Recursive Functions.

A function f is said to be recursive iff it can be obtained from the initial functions by finite number of applications of substitution, primitive recursion and restricted operator.

Note: Every Primitive recursive function is recursive. But the converse is false.

Q. Show that the function 1( , )f x y x y is primitive recursive.

1( , )f x y x y (definition of 1f ) ……..(1)

1f is a function of two variables, that is, 21 :f

Now # 11 : gf

Therefore # 1g , that is, g is a function of a single variable and # # 2h g = 1 + 2 = 3, that is, h is a function of three variables.

We require g and h satisfying the above criteria.

Now,

1

1

1

( ,0) 0 (using (1))( ,0)( ,0) ( )

f x xf x xf x g x

Therefore, 11( ) ( )g x x P x ……..(2) (definition of projection function)

Also

1( , 1) ( 1)f x y x y (using (1))

1( , 1) ( ) 1f x y x y

1 1( , 1) ( , ) 1f x y f x y (using (1) again)

Page 4: theory of computation notes

1 1( , 1) ( , )f x y S f x y (definition of successor function)

31 3 1( , 1) ( , , ( , ))f x y S P x y f x y (definition of projection function)

1 1( , 1) , , ( , )f x y h x y f x y

where h is the composition of S and 33P , that is, 3

3,h Sub S P ……..(3)

Hence

1

1 1

( ,0) ( )( , 1) , , ( , )

f x g xf x y h x y f x y

………(4)

where g and h are given by (2) and (3) above respectively. Here (4) is nothing but primitive recursion.

Thus the function 1f R is given by

1 31 3( , ) , ,R g h R P Sub S P

We see that 1f is obtained by applying composition and primitive recursion, a finite number of

times to the initial functions 1 31 3, ,P S P .

Hence 1f is primitive recursive.

Q. Show that the function 2 ( , )f x y x y is primitive recursive.

2 ( , )f x y x y (definition of 2f ) ……..(1)

2f is a function of two variables, that is, 22 :f

Now # 12 : gf

Therefore # 1g , that is, g is a function of a single variable and # # 2h g = 1 + 2 = 3, that is, h is a function of three variables.

We require g and h satisfying the above criteria.

Now,

Page 5: theory of computation notes

2

1

1

( ,0) 0 (using (1))( ,0) 0( ,0) ( )

f x xf xf x g x

Therefore, 10( ) 0 ( )g x C x ……..(2) (definition of constant function)

Also

2 ( , 1) ( 1)f x y x y (using (1))

2 ( , 1)f x y x y x

2 2( , 1) ( , )f x y f x y x (using (1) again)

Let 1( , )f x y x y . Then we know that 1f is primitive recursive. So

2 1 2( , 1) ( , ),f x y f f x y x (definition of the function 1f )

3 32 1 3 2 1 2( , 1) , , ( , ) , , , ( , )f x y f P x y f x y P x y f x y (definition of projection function)

3 32 1 3 1 2( , 1) , , , , ( , )f x y Sub f P P x y f x y

2 2( , 1) , , ( , )f x y h x y f x y

where h is the composition of 1f , 33P and 3

1P , that is, 3 31 3 1, ,h Sub f P P ……..(3)

Hence

2

2 2

( ,0) ( )( , 1) , , ( , )

f x g xf x y h x y f x y

………(4)

where g and h are given by (2) and (3) above respectively. Here (4) is nothing but primitive recursion.

Thus the function 2f R is given by

1 3 30 1 3 1( , ) , , ,R g h R C Sub f P P

where 1( , )f x y x y is already primitive recursive.

Page 6: theory of computation notes

We see that 2f is obtained by applying composition and primitive recursion, a finite number of

times to the primitive recursive functions 1 30 1 3, ,C f P and 3

1P .

Hence 2f is primitive recursive.

Q. Show that the function 3 ( , ) yf x y x is primitive recursive.

3 ( , ) yf x y x (definition of 3f ) ……..(1)

3f is a function of two variables, that is, 23 :f

Now # 13 : gf

Therefore # 1g , that is, g is a function of a single variable and # # 2h g = 1 + 2 = 3, that is, h is a function of three variables.

We require g and h satisfying the above criteria.

Now,

03

3

3

( ,0) (using (1))( ,0) 1( ,0) ( )

f x xf xf x g x

Therefore, 11( ) 1 ( )g x C x ……..(2) (definition of constant function)

Also

13( , 1) yf x y x (using (1))

3( , 1) yf x y x x

3 3( , 1) ( , )f x y f x y x (using (1) again)

Let 2 ( , )f x y x y . Then we know that 2f is primitive recursive. So

3 2 3( , 1) ( , ),f x y f f x y x (definition of the function 2f )

3 33 2 3 3 1 3( , 1) , , ( , ) , , , ( , )f x y f P x y f x y P x y f x y (definition of projection function)

3 33 2 3 1 3( , 1) , , , , ( , )f x y Sub f P P x y f x y

Page 7: theory of computation notes

2 3( , 1) , , ( , )f x y h x y f x y

where h is the composition of 2f , 33P and 3

1P , that is, 3 32 3 1, ,h Sub f P P ……..(3)

Hence

3

3 3

( ,0) ( )( , 1) , , ( , )

f x g xf x y h x y f x y

………(4)

where g and h are given by (2) and (3) above respectively. Here (4) is nothing but primitive recursion.

Thus the function 3f R is given by

1 3 33 1 2 3 1( , ) , , ,f R g h R C Sub f P P

where 2 ( , )f x y x y is already primitive recursive.

We see that 3f is obtained by applying composition and primitive recursion, a finite number of

times to the primitive recursive functions 1 31 2 3, ,C f P and 3

1P .

Hence 3f is primitive recursive.

Q. Show that the function ( ) !f n n is primitive recursive.

( ) !f n n (definition of f ) ……..(1)

f is a function of two variables, that is, :f

Now 0 1:f

Therefore,

(0) 0! (using (1))(0) 1(0)

fff k

Therefore, 111 ( )k C x ……..(2) (definition of constant function)

Also

( 1) ( 1)!f y y (using (1))

Page 8: theory of computation notes

( 1) ( 1) !f y y y

( 1) ! !f y y y y

( 1) ( ) ( )f y y f y f y

Let 2 ( , )f x y x y . Then we know that 2f is primitive recursive. So

22 2( 1) , ( ) , ( )f y f y f y P y f y where the projection function 2

2P is primitive recursive

21 2 2( 1) , , ( )f y f f P y f y where 1( , )f x y x y is a primitive recursive function

21 2 2( 1) , , , ( )f y Sub f f P y f y

( 1) , ( )f y h y f y

where h is the composition of 1f , 2f and 22P , that is, 2

1 2 2, ,h Sub f f P ……..(3)

Hence

(0)( 1) , ( )

f kf y h y f y

………(4)

where k and h are given by (2) and (3) above respectively. Here (4) is nothing but primitive recursion.

Thus the function f R is given by

21 2 2( ) , ,f R h R Sub f f P

where 1( , )f x y x y and 2 ( , )f x y x y are already primitive recursive.

We see that f is obtained by applying composition and primitive recursion, a finite number of times to the primitive recursive functions 2

1 2 2, ,f f P .

Hence f is primitive recursive.

Page 9: theory of computation notes

Q. Show that the predecessor function 1 0

( )0 0x if x

pred xif x

is primitive recursive.

Let 1 0

( ) ( )0 0x if x

p x pred xif x

……….(1)

Here :p , that is, 0 1:p .

Therefore,

(0) 0 (using (1))(0) 0

pp k

So, 100 ( )k C x ………(2) (definition of constant function)

Also,

( 1) ( 1) 1p y y (using (1))

( 1)p y y

21( 1) , ( )p y P y p y

( 1) , ( )p y h y p y

where 21h P ……..(3)

Hence

(0)( 1) , ( )

p kp y h y p y

……..(4)

where k and h are given by (2) and (3) above respectively. Here (4) is nothing but primitive recursion.

Thus the function pred p R is given by 21( ) ( )pred p R h R P .

We see that ( )pred x is obtained by applying primitive recursion, a finite number of times to the

primitive recursive function 21P . Hence ( )pred x itself is primitive recursive.

Page 10: theory of computation notes

Q. Show that the Arithmetical difference function 2:

defined by

0 x y if x y

x yif x y

is primitive recursive.

Let

be denoted by f, that is, ( , )x y f x y

.

Then

( , )0 x y if x y

f x yif x y

……..(1)

Here f is a function of two variables, that is, 2:f .

Now, we know that # 1: gf .

Therefore, # 1g , that is, g is a function of a single variable and # # 2h g = 1 + 2 = 3, that is, h is a function of three variables.

We require g and h satisfying the above criteria.

Now,

( ,0) 0 (using (1))( ,0)( ,0) ( )

f x xf x xf x g x

Therefore, 11( ) ( )g x x P x ……….(2) (definition of projection function)

Also

( , 1) ( 1)f x y x y (using (1))

( , 1) 1f x y x y

( , 1) ( , ) 1f x y f x y (using (1) again)

( , 1) ( , )f x y pred f x y where 1 0

( )0 0x if x

pred xif x

is primitive recursive

33( , 1) , , ( , )f x y pred P x y f x y

33( , 1) , , , ( , )f x y Sub pred P x y f x y

Page 11: theory of computation notes

( , 1) , , ( , )f x y h x y f x y

where 33,h Sub pred P ……….(3)

Hence

( ,0) ( )( , 1) , , ( , )

f x g xf x y h x y f x y

……...(4)

where g and h are given by (2) and (3) respectively. Here (4) is nothing but primitive recursion.

Thus the function f R

is given by 1 31 3( , ) , ,f R g h R P Sub pred P

where ( )pred x is already primitive recursive.

We see that f is obtained by applying composition and primitive recursion, a finite number of

times to the primitive recursive functions 1 31 3, ,P pred P . Hence f or

itself is primitive recursive.

Note-1: ( , )f x y x y is primitive recursive since we can write x y x y y x

where

is arithmetic difference, and both addition (+) and arithmetical difference (

) are

primitive recursive. Notice that x y is expressed as the composition of + and

.

Note-2: ( , ) min( , )f x y x y is primitive recursive since we can write min( , )x y x x y

where

is arithmetic difference, and

is primitive recursive. Notice that min( , )x y is

expressed as the composition of

and

.

TURING MACHINE MODEL

The Turing Machine (TM) is a mathematical model of a general purpose computer. The TM can be thought of as a finite state automaton connected to a Read-Write (R/W) head. It has one tape which is divided into a smaller number of cells.

Page 12: theory of computation notes

Each cell can store only one symbol. The input to and output from the finite state automaton are affected by the R/W head which can examine one cell at a time. In one move, the machine examines the present symbol under the R/W head on the tape and the present state of an automaton to determine

(1) A new symbol to be written on the tape in the cell under the R/W head. (2) A motion of the R/W head along the tape; either the head moves one cell left (L) or one

cell right (R). (3) The next state of the automaton. (4) Whether to halt or not.

We will try to construct a Turing Machine (TM) that can compute the Primitive recursive functions. For this purpose, (3) and (4) above are not required to be part of the TM.

The above model can be defined as follows:

Def. A Turing machine M is a 7-tuple 0( , , , , , , )Q q b F where

(1) Q is a finite non-empty set of states (2) is a non-empty set of tape symbols (3) b is the blank symbol (4) is a non-empty set of input symbols and Σ Γ and Σb . (5) is the transition function mapping the states of finite automaton and tape symbols to

states, tape symbols and movement of the head, that is, Γ Γ ,Q Q L R .

(6) 0q Q is the initial state (7) F Q is the set of final states

Page 13: theory of computation notes

Note-1: The acceptability of a string is decided by the reachability from the initial state to some final state. Final states are also called Accepting States.

Note-2: may not be defined for some elements of ΓQ . In such a case the Turing machine halts.

Representation of a Turing machine by Instantaneous descriptions (ID):

Snapshots of a TM in action can be used to describe a TM. These give instantaneous descriptions (ID) of a TM. An ID of a TM is defined in terms of the entire input string and the current state.

Defn. of ID: An ID of a Turing machine M is a string where is the current state of M, the entire input string is split into , the first symbol of is the current symbol a under R/W head and has all the subsequent symbols of the input string, and the string is the substring of the input string formed by all the symbols to the left of a.

For example, consider

Page 14: theory of computation notes

(1) For constructing the ID, we insert the current state into the input string, to the left of the symbol under R/W head.

(2) The blank symbol is always present at both ends of the input string. (3) The blank symbol may occur as part of the left or right substring.

Kurt Godel (1934) proposed that primitive recursive functions can be computed by a finite procedure, that is, an algorithm. He also hypothesized that any function computable by a finite procedure can be specified by Recursive function.

Around 1936, Turing and Church independently designed a computing machine (later called TM) which can carry out a finite procedure.

Page 15: theory of computation notes

Turing assumed that, while computing, a person writes symbols on a one-dimensional paper which can be viewed as a tape divided into cells. He scans the cells one at a time and performs one of the three simple operations:

(i) Writing a new symbol in the cell he is scanning (ii) Moving to the cell on the left of the present cell (iii) Moving to the cell on the right of the present cell

These observations led Turing to propose a computing machine, later known as Turing machine.

In the present model for computation of Primitive recursive functions, the transition function represents only one of three basic operations:

(i) Writing a new symbol in the cell scanned (ii) Moving to the left cell (iii) Moving to the right cell

Each operation is followed by a change of state.

Suppose the Turing machine M is in state q and scans ia . Suppose ja is written and M enters

state q . Then this operation is represented by i jqa a q . Similarly, the other two operations are

represented by iqa Lq and iqa Rq . Thus the transition function can be represented by a set P of

quadruples. Each quadruple induces a change of ID’s. For example, i jqa a q induces

1 2 1 1 2 1 1.... .... .... ....i i n i j i na a a qa a a a a q a a a

iqa Lq induces

1 2 1 1 2 2 1.... .... .... ....i i n i i i na a a qa a a a a q a a a

iqa Rq induces

1 2 1 1 2 1.... .... .... ....i i n i i na a a qa a a a a q a a

When we require M to perform some computation, we first “feed” the input by the initial tape expression denoted by X. So, 0q X is the initial ID for the given input.

For computing with the given input X, the TM processes X using appropriate quadruples in P. As a result, we have 0 1 2ID IDq X . When an ID say IDn is reached, which cannot be changed using any quadruple in P, then the TM halts. IDn is called Terminal ID. Actually,

iq a is a terminal ID, if there is no quadruple starting with iq a . The terminal ID is called the “result” of X.

Page 16: theory of computation notes

Note: The symbol * denotes the reflexive transitive closure of the relation . If

*

1I In then

we can split this as 1 2I I In for some ID’s 2 1I ,....., In .

The processing of input strings is done by “moves by ID’s”.

COMPUTING PRIMITIVE RECURSIVE FUNCTIONS USING TM

Suppose we want to construct a TM which can compute 1 2, ,..., mf x x x over N for given

arguments 1 2, ,..., ma a a . Initially the input 1 2, ,..., ma a a appears on the input tape separated by

markers 1 2, ,..., mx x x .

The computed value 1 2, ,..., mf a a a say c appears on the input tape once the computation is over. To locate c, we need another marker, say, y.

The value c appears to the right of mx and to the left of y. To make the construction simpler, we use tally notation to represent the elements of N. In tally notation, 0 is represented by a string of b’s. A positive integer n is represented by a string consisting of n 1’s. So the initial tape expression takes the form 1 2

1 21 1 ........1 maa amx x x by .

As a result of computation, the initial ID 1 20 1 21 1 ........1 maa a

mq x x x by is changed to a terminal ID of

the form 1 21 21 1 ........1 1maa a c

mx x x q y or 1 21 21 1 ........1 1maa a c

mx x q x y etc. for some q Q .

In fact, the position of q in a terminal ID is immaterial and it can appear anywhere in the terminal ID. The computed value is found between mx and y.

Def. Turing Computable Function

A function 1 2, ,..., mf x x x is said to be Turing computable for arguments 1 2, ,..., ma a a if there exists a Turing machine M for which

1 2*

0 1 2 n1 1 ........1 IDmaa amq x x x by

where IDn is a terminal ID containing 1 2, ,..., mf a a a to the left of y.

Note: One can prove that the partial recursive functions are Turing computable.

Page 17: theory of computation notes

Question: Construct a Turing Machine that can compute the successor function. Further compute (1)S and (2)S showing the moves by ID and describe the transition function by specifying the set P of quadruples.

Solution: The successor function S is defined by 1 1 1S a a for all 1 0a . So the initial tape

expression can be taken as 111aX x by . At the end of the computation, we require 1 11a to appear

to the left of y. Hence we define a Turing Machine by taking 0 1 2 8, , ,.....,Q q q q q and

1,1, ,b x y . The transition function described by the set P will be specified later.

The operations of the Turing Machine M can be explained as follows:

(1) If M starts from the initial ID (that is, 10 11aq x by ) then the R/W head replaces the first 1 it

encounters by b ( 0 11q bq ) and M enters state 1q . Afterwards it moves right until it

encounters y. ( 1 1q bRq , 1 11q Rq , 1 1 1q x Rq )

(2) y is replaced by 1 and M enters 2q ( 1 21q y q ). The R/W head then moves right until the end

of tape (represented by blank) is reached ( 2 21q Rq ). Once blank is encountered, y is added

to it ( 2 3q byq ) and M enters 3q .

(3) Then the R/W head moves to left and the state is not changed until 1x is encountered (

3 31q Lq , 3 3q bLq ).

(4) On encountering 1x , the R/W head moves to left and M enters 4q ( 3 1 4q x Lq ). Once again

the R/W head moves to left till the left end of the input string is reached ( 4 41q Lq ).

(5) The leftmost blank (written in step (1)) is replaced by 1 and M enters 0q ( 4 01q b q ).

Thus at the end of operations (1)-(5) the input part remains unaffected but the first 1 is added to the left of y. Operations (1) to (5) are repeated until all the 1’s of the input part (that is in 11a )are exhausted and 11…..1 ( 1a times) appear to the left of y. Now the current state is 0q and current

symbol is 1x .

(6) M in state 0q scans 1x , moves right and enters 5q ( 0 1 5q x Rq ). It continues to move right

until it meets y ( 5 5q bRq , 5 5 1q Rq ).

(7) On encountering y, the R/W head moves to the left and M enters 6q ( 5 6q yLq ). After this,

the head moves left until it encounters b appearing to the left of 11a of the output part (

6 61q Lq ). Thus b is changed to 1 and M enters 7q ( 6 71q b q ).

(8) Once M is in 7q , the head continues to move to the left ( 7 71q Lq ) and on encountering 1x ,

M moves left and enters 8q ( 7 1 8q x Lq ).

Page 18: theory of computation notes

The machine M halts as there is no quadruple starting with 8q and the terminal ID is 1 1 1

8 11 1 .a aq x y

Computing (1)S by moves by ID:

0 1 1 1 1 1 1 1 1 1 1 2

1 2 1 3 1 3 1 3 4 1

0 1 1 5 1 5 1 5 1 6

1 7 1 7 8 1

1 11 1 1 1 1

1 1 1 1 1 1 1 1 1 11 1 1 1 11 1 11

q x by q bx by bq x by bx q by bx bq y bx bqbx b q b bx b q y bx bq y bx q b y bq x b yq x b y x q b y x bq y x b q y x bq yx q y x q y q x y

The Turing Machine halts as there is no quadruple starting with 8q , and therefore the terminal ID

is 8 11 11q x y .

Computing (2)S :

*

0 1 1 1 1 1 1 2

*

1 2 1 3 1 3 4 1 4 1*

0 1 1 1 1 1 1 2 1 2*

1 3 1 3 4 1 0 1

*

1 5

11 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1 1 11

1 11 1 11 1 11 11 11

11 11 11

q x by q b x by b x bq y b x bq

b x b q b b x b q y b x q b y b q x b y bq x b y

q x b y q bx b y bx b q y bx b q bx b q b

bx b q y bx q b y bq x b y q x b y

x q b y x

1 5 1 6 1 6

1 7 1 7 8 1

11 11 1 1 11 1111 1 11 11 111 11 111

b q y x b q y x bq yx q y x q y q x y

The Turing Machine halts as there is no quadruple starting with 8q , and therefore the terminal ID

is 8 111 111q x y .

The transition function is described by the set P of quadruples below:

(1) 0 1 0 1 51 , q bq q x Rq

(2) 1 1 1 1 1 1 2 1 1, , 1 , 1q bRq q x Rq q y q q Rq

(3) 2 2 2 31 , q Rq q byq

(4) 3 3 3 3 3 1 41 , , q Lq q bLq q x Lq

(5) 4 0 4 41 , 1q b q q Lq

(6) 5 5 5 5 5 6, 1 , q bRq q Rq q yLq

(7) 6 7 6 61 , 1q b q q Lq

(8) 7 7 7 1 81 , q Lq q x Lq

Page 19: theory of computation notes

In a similar way, we can construct a Turing Machine

(1) for computing the constant function (2) for computing the projection function (3) that can perform substitution (or composition) (4) that can perform primitive recursion (5) that can perform unbounded minimization

GODELIZATION OR ARITHMETIZATION OR GODEL NUMBERING

The essential feature of Godelization is the ability to encode a sequence of numbers in a single value.

The coding scheme utilizes the unique decomposition of a natural number into a product of primes. Such codes are called Godel Numberings after German logician Kurt Godel.

GODEL NUMBERING

Def. A sequence 0 1, ,....., nx x x of natural numbers of length (n + 1) is encoded by

10 1

0

, ,....., ( ) in

xn n

i

gn x x x pn i

or 0 1 21 11 10 1, ,....., (0) (1) (2) ( ) nx xx x

n ngn x x x pn pn pn pn n

or 0 1 21 11 10 1, ,....., 2 3 5 ( ) nx xx x

n ngn x x x pn n

where ( )pn n denotes the (n + 1)th prime number.

For example, pn(0) = 2, pn(1) = 3, pn(2) = 5, pn(3) = 7, pn(4) = 11 etc.

Sequence Encoding (Godel number) 1, 2 22.33 = 108

0, 1, 3 21.32.54 = 11250 0, 1, 0, 1 21.32.51.72 = 4410

Q. Encode the sequence 1, 0, 1, 0, 1 by using Godelization and state the corresponding Godel Number.

The sequence is 1, 0, 1, 0, 1.

The encoding is 22.31.52.71.112 = 254100.

Hence the corresponding Godel Number is 254100 or 4 1, 0, 1, 0, 1 254100gn .

Page 20: theory of computation notes

The Godel numbering function encode a fixed number of arguments. A Godel numbering function can be constructed in which the number of elements to be encoded is variable.

Suppose f is a one variable primitive recursive function with input 0, 1, 2, ….., n. It defines a sequence f(0), f(1), f(2),….., f(n) of length (n + 1).

Then the bounded product ( ) 1

0

( )y

f i

ipn i

encodes the first (y + 1) values of f, and is denoted

by ( )fgn y .

Q. Compute (2)fgn where f is the factorial function.

Clearly, i =0, 1, 2 and f(n) = n!

Therefore, f(0) = 0! = 1, f(1) = 1! = 1, f(2) = 2! = 2.

So

2

( ) 1

0(0) 1 (1) 1 (2) 1

1 1 1 1 2 1

2 2 3

(2)

( )

2 3 52 3 52 3 54500

f

f i

if f f

gn

pn i

THEOREM: Suppose f be an (n + 1) variable function and be the encoding function defined

from f by 1 2, ,...., , 1

1 20

( , ,...., , ) ( ) n

yf x x x i

f ni

gn x x x y pn i

. Then f is primitive recursive if

and only if fgn is primitive recursive.

DECISION PROBLEMS: DECIDABLE AND UNDECIDABLE PROBLEMS

A decision problem consists of a set of questions whose answers are either yes or no. A solution to a decision problem is an effective procedure that determines the answer for each question in the set.

A decision problem is undecidable if there is no algorithm (effective procedure) that solves the problem.

Page 21: theory of computation notes

The Church-Turing thesis asserts that a Turing Machine can be designed to solve any decision problem that is solvable by an effective procedure.

Consequently, to establish that a problem is unsolvable, it suffices to show that there is no Turing Machine solution.

Def. (Decision Problem)

A decision problem DP is a set of questions, each of which has a YES or NO answer.

A decision problem usually consists of an infinite number of related questions. For example, the problem PSQ of determining whether an arbitrary natural number is a perfect square, consists of the following questions:

P0: Is 0 a perfect square?

P1: Is 1 a perfect square?

P2: Is 2 a perfect square?

….

….

Def. (Solution to a decision problem)

A solution to a decision problem DP is an algorithm that determines the appropriate answer to every question DPiP . An algorithm that solves a decision problem should be

(1) Complete: It produces an answer, either positive or negative, to each question in the problem domain.

(2) Mechanistic: It consists of a finite sequence of instructions, each of which can be carried out without requiring insight, ingenuity and guesswork.

(3) Deterministic: When presented with identical input, it always produces the same result.

A procedure that satisfies the preceding properties is called an effective procedure or an algorithm.

The computations of a Turing Machine are mechanistic and deterministic. The Turing machine that halts for every input string is also complete. Thus Turing Machines can be used (theoretically) to construct solutions for decision problems. A decision problem is answered affirmatively if the input is accepted by the TM, and negatively if it is rejected.

Page 22: theory of computation notes

Def. (Halting and Abnormal termination of TM)

A Turing Machine (TM) halts when it encounters a state/symbol-pair, for which no transition is defined, that is, ( , )q X is undefined. When we say that a computation halts, we mean that it terminates in a normal fashion as described above.

A transition from tape position zero may specify a move to the left of the boundary of the tape. When this occurs, the computation is said to terminate abnormally.

TURING MACHINES AS LANGUAGE ACCEPTORS

Def. (Acceptance of a string by a Turing Machine)

Let 0M , , , , , ,Q q b F be a Turing Machine. A string *u is accepted by final state if

the computation of M with input u halts in a final state. A computation that terminates abnormally, rejects the input regardless of the final state of the machine.

NOTE: L(M) is the language of the Turing Machine M, that is, it is the set of all strings accepted by M.

Def. (Recursively Enumerable Language)

A language accepted by a Turing Machine is called a Recursively Enumerable Language.

NOTE: The ability of a TM to move in both directions, and also process blanks (b’s) introduces the possibility that the machine may not halt for a particular input, in a final state.

Def. (Recursive Languages)

Those languages with Turing Machines that do halt eventually, for all inputs, regardless of whether or not they accept by final state, are called Recursive Languages.

Turing Machines that always halt, regardless of whether or not they accept, are a good model of an algorithm. If an algorithm to solve a given problem exists, then we say that the problem is decidable.

Def. (Decidable problems)

A decision problem is decidable if it has a representation in which the set of accepted input strings form a recursive language.

THE CHURCH-TURING THESIS FOR DECISION PROBLEMS

(Statement) There is an effective procedure to solve a decision problem if and only if there is a Turing Machine that halts for all input strings and solves the problem.

Page 23: theory of computation notes

Note-1: The Church-Turing thesis is not a mathematical theorem; it cannot be proved. This would require a formal definition of an effective procedure which is not possible. The claim could however be disproved, by discovering an algorithm, that cannot be computed by a Turing Machine. There are a lot of evidence that such an algorithm will not be found. The strongest evidence supporting the Church-Turing thesis is that all known algorithms (effective procedures) have been able to be transformed into equivalent TM’s.

Note-2: The Church-Turing thesis asserts that a decision problem DP has a solution if and only if there is a Turing Machine that determines the answer for every instance DPiP . If no such Turing Machine exists, the problem is said to be Undecidable. If a problem cannot be solved by a Turing Machine, it clearly cannot be solved by a resource-limited machine (a machine with finite memory and fixed computing speed).

Note-3: Undecidable problems are also called Unsolvable problems.

Def. (Undecidable Problems)

A decision problem is undecidable if there is no algorithm that solves the problem, or equivalently, if the problem cannot be solved by a Turing Machine.

SOME DECIDABLE PROBLEMS

1) The Decision problem PSQ of determining whether an arbitrary natural number is a perfect square is decidable (There is a 3-tape Turing Machine that solves the problem).

2) The problem of determining whether there is a path from a node vi to a node vj in a directed graph is decidable. (A non-deterministic 2-tape Turing Machine can be designed to solve the path problem)

SOME UNDECIDABLE PROBLEMS

1) The Halting Problem (HP) for Turing Machine is undecidable. The HP is stated as follows: Given an arbitrary Turing Machine M with input alphabet 0,1 and a string

*w , the problem is to determine whether or not M halts for the arbitrary input w. 2) The Posts Correspondence Problem (PCP) over for 2 is undecidable. The PCP is

stated as follows: For two lists 1 2, ,......, nx x x x and 1 2, ,......, ny y y y of non-empty

strings over an alphabet , the PCP is to determine whether or not there exist 1 2, ,......, ki i i

where 1 ji n such that 1 2 1 2

..... .....k ki i i i i ix x x y y y .

Page 24: theory of computation notes

Q. Does PCP with 3, ,x b bab ba and 3 , ,y b ba a have a solution?

By Trial and Error, we find that there is a solution:

Taking k = 4, we have

2 1 1 3 2 1 1 3

3 3 3

x x x x y y y ybab b b ba ba b b a

Thus the PCP has a solution in this case. However, there is no algorithm that solves every instance of the PCP (till now). Hence PCP is undecidable.

MULTI-TAPE OR k-TAPE TURING MACHINE

A k-tape Turing Machine consists of k tapes and k independent tape heads. The states and alphabet of a multi-tape machine is the same as in a standard Turing Machine. The TM reads the tapes simultaneously but has only one state. This is depicted by connecting each of the independent tape heads to a single control indicating the current state.

A transition is determined by the state and the symbols scanned by each of the tape heads. A transition in a multi-tape machine may

(1) Change the state (2) Write a symbol on each of the tapes

Page 25: theory of computation notes

(3) Independently re-position each of the tape heads (left-L, right-R, stationary-S)

For example, a transition of a 2-tape TM scanning 1x on Tape-1 and 2x on Tape-2 is written as

1 2 1 1 2 2, , ; , ; ,i jq x x q y d y d where ,i ix y (tape symbols) and , ,id L R S , iq is current

state, jq is the next state. This transition causes the TM to write iy on Tape-i. The symbol idspecifies the direction of movement of tape head i.

The input to a multi-tape machine is placed in the standard position on Tape-1. All the other tapes are assumed to be blank. The tape heads originally scan the leftmost position of each tape. Any tape head attempting to move to the left of the boundary of its tape, terminates the computation abnormally.

Note-1: A standard TM is a multi-tape TM with a single tape.

Note-2: (Theorem) A language L is accepted by a multi-tape TM if and only if it is accepted by a standard TM.

Non-Deterministic Turing Machine

In case of a deterministic Turing Machine (that is, the Turing Machine we have discussed till now), the processing of an input symbol (on tape) results in the transition to a unique ID (instantaneous description). So, the processing of an input string results in a chain of ID’s such as

1 2 nID ID ID ID

Let us write this chain as

1 2 nID ID ID ID

A natural generalization can be obtained by allowing transition to several ID’s as a result of the processing of an input symbol. This can be represented by using tree structures.

Page 26: theory of computation notes

A string *w is said to be accepted by a NDTM (non-deterministic Turing Machine) if there exists a sequence of moves starting from the initial ID to an ID which corresponds to an accepting state or final state.

A NDTM uses “guess and check” strategy to determine whether the non-deterministic guess leads to a solution.

Def. (Non-deterministic Turing Machine)

A non-deterministic Turing Machine or NDTM is same as a standard Turing Machine except that it has a transition function such that for each state q and tape symbol X, ,q X is a set of triples

1 1 1 2 2 2, , , , , ,......, , ,k k kq Y d q Y d q Y d

where k is any finite integer. The NDTM can choose, at each step, any one of the triples to be the next move.

Def. (Acceptance of a string by a NDTM)

A NDTM accepts an input *w if there is any sequence of choices of move that leads from the initial ID with w as input, to an ID, with an accepting state or final state. The existence of other choices that do not lead to an accepting state is irrelevant.

Note-1: The language of a NDTM say NM is the set of all strings *w accepted by the

machine. It is denoted by NML .

Note-2: In case of NDTM’s, whenever the transition function indicates that more than one action is possible, a computation arbitrarily chooses one of the transitions.

Note-3: Non-determinism does not increase the capabilities of a Turing computation; the languages accepted by the NDTM’s are precisely those accepted by deterministic TM’s. It is due to this theorem.

Theorem: If NM is a non-deterministic Turing Machine, then there is a deterministic Turing

Machine DM such that N DM ML L .

Computational complexity

Complexity analysis allows us to classify decision problems (DP’s) upon the feasibility of their solutions. A solvable problem may have no practical solutions, that is, every algorithmic solution may require an unacceptable amount of resources (that is, time and memory).

Page 27: theory of computation notes

The class P of decision problems that are considered tractable is defined as the set of problems solvable in polynomial time by a deterministic Turing Machine.

The class NP consists of all decision problems that can be solved by non-deterministic polynomial time algorithms.

Clearly P is a subset of NP. It is currently unknown if these two classes of problems are identical, that is, it is not known if P = NP. This is because a non-deterministic algorithm uses a guess and check strategy to determine whether the non-deterministic guess is a solution.

The time complexity of a Turing Machine is measured by the number of transitions in the computation. That is, the time of computation of a Turing Machine is quantified by the number of transitions processed. Rates of growth are commonly used to describe the complexity of a Turing Machine.

The complexity of a language is determined by the complexities of the Turing Machines that accept the language.

Def. (Time complexity of a standard Turing Machine)

Let M be a standard Turing Machine. The time complexity of M is the function M : N Ntc

such that M ( )tc n is the maximum number of transitions processed by a computation of M when initiated with an input string of length n.

Note-1: When evaluating the time complexity of a Turing Machine, we assume that the computations terminate for every input string.

Note-2: We say that a language is accepted in deterministic time f(n) if there is a deterministic Turing Machine M with M ( ) ( )tc n f n for all Nn .

For example, suppose M is a Turing Machine accepting the palindromes over = ,a b . Then it

can be shown that 21

M1

( 1)( 2) 3 2( )2 2

n

i

n n n ntc n i

RATES OF GROWTH

Time complexity is often represented by the rate of growth of a function rather than the function itself. The rate of growth of a function measures the increase of the function values as the input n gets arbitrarily large.

Page 28: theory of computation notes

Def. Let f and g be one variable, number theoretic functions. The function f is said to be of order g, written ( )f O g (f is big-oh of g) if there is a positive constant c and a natural number 0n

such that ( ) ( )f n cg n for all 0n n .

Def. Two functions f and g are said to have the same rate of growth if ( )f O g and also ( )g O f .

Question: Show that 2( ) 2 5f n n n and 2( )g n n have the same rate of growth.

Solution:

2 21.( 2 5) 1n n n n

Therefore, 0 0( ) . ( ) ( 1, 1)g n c f n n n c n

So ( )g O f .

Since 22 2n n and 25 5n 1n , so

2 2 2 2 2( ) 2 5 2 5 8 8. ( )f n n n n n n n g n 1n

Therefore, 1( ) . ( )f n c g n 1n n 1 1( 8, 1)c n

So ( )f O g .

Hence f and g have the same rate of growth.

Example: Let 2( )f n n and 3( )g n n . Then ( )f O g since 2 3n n 1n .

Thus we can write 2 3( )n O n .

But ( )g O f . Let us suppose that 3 2( )n O n .

Then there exists constants C and 0n such that

3 2.n C n 0n n ……..(1)

Choose 1n to be the maximum of 0 1n and c + 1.

Then 3 2 21 1 1 1. .n n n C n and 1 0n n

which contradicts inequality (1).

Page 29: theory of computation notes

This is seen as follows:

If 1 0 01 max{ 1, 1}n n n c , then

3 2 2 23 21 0 0 0 0 0 11 1 1 1 1 1 .n n n n c n c n c n

On the other hand, if 1 01 max{ 1, 1}n c n c , then

3 2 23 21 11 1 1 1 .n c c c c c c n

Thus our assumption is false and 3 2( )n O n .

Def. (Polynomial)

A polynomial with integral coefficients is a function of the form

11 1 0( ) . . .r r

r rf n C n C n C n C

where 1 00, ,.....,r rC C C are integers and r is a positive integer. iC are called coefficients of the polynomial f(x) and r its degree.

Note-1: A polynomial with integral coefficients defines a function from NN.

Note-2: The value of a polynomial may be negative for some values of n. For example, if 2( ) 3 4f n n n then (0) 4, (1) 6f f etc.

Again, for example, if 2( ) 1g n n then g is negative for all Nn .

Note-3: The absolute value function if 0

if 0i i

ii i

is used to transform an arbitrary polynomial

into a number theoretic function. Composing a polynomial f with absolute value produces a number theoretic function : N Nf .

Def. The rate of growth of a polynomial f is defined to be the rate of growth of f .

Theorem: Let f(n) be a polynomial of degree r. Then

(1) ( )rf O n (2) 2 ( )n O f (3) ( ) for all kf O n k r (4) ( ) for all kf O n k r

Other functions used in measuring the performance of algorithms are logarithmic, exponential and factorial functions.

Page 30: theory of computation notes

Theorem: Let r be a natural number and 1, 1a b be real numbers. Then

(1) log ( ) ( )a n O n (2) (log ( ))an O n (3) ( )r nn O b (4) ( )n rb O n (5) ( !)nb O n (6)

! ( )nn O b .

Def. (Polynomially Bounded Function)

A function f is said to be polynomially bounded if ( )rf O n for some natural number r.

Note-1: ( )rf O n (where 1a ) is bounded by the polynomial 2n . Therefore 2log ( ) ( )an n O n where 1a .

Note-2: Exponential and Factorial functions are not polynomially bounded.

Question: Which functions grows faster : 2n or 2log ( )n n ? Why?

Solution: 2n grows faster than 2log ( )n n since 22log ( ) ( )n n O n and 2 (2 )nn O but

22 ( )n O n .

Big-Oh Hierarchy:

The efficiency of an algorithm is characterized by its rate of growth. Lesser the rate of growth, the more efficient is the algorithm.

Page 31: theory of computation notes

Def. (Polynomial Time Algorithm)

A polynomial time algorithm is an algorithm whose time complexity is polynomially bounded, that is, M ( ) ( )rtc n O n for some Nr where M is a standard Turing Machine that computes the algorithm.

Note: The distinction between polynomial and non-polynomial algorithms is apparent when considering the number of transitions of a Turing Machine computation, as the length of input increases. Enormous resources are required by an algorithm whose time complexity is not polynomial.

Number of transitions of a Turing Machine with time complexity with input of length n:

n M ( )tc n

Input log2(n) n n2 n3 2n n! 5 2 5 25 125 32 120 10 3 10 100 1000 1024 3628800 50 5 50 2500 125000 1.1 x 1015 3 x 1064

100 6 100 10000 1000000 1.2 x 1030 > 10157

200 7 200 40000 8000000 1.3 x 1060 > 10374

Theorem: Let L be a language accepted by a k-tape deterministic Turing Machine M with time complexity M ( ) ( )tc n f n . Then L is accepted by a standard Turing Machine M with time

complexity 2M ( ) ( )tc n O f n .

Note: An example of a function between the polynomials and exponentials is 2log nn . This function grows faster than any polynomial in n, but grows more slowly than 2cn for any 0c .

Page 32: theory of computation notes

NON-DETERMINISTIC COMPLEXITY

Non-deterministic computations are fundamentally different from their deterministic counterparts. A deterministic machine often solves a decision problem (DP) by generating a solution in a systematic manner. A non-deterministic machine need only determine if one of the possibilities is a solution.

Example:

Consider the problem of deciding whether a natural number n is a composite (that is, not a prime). A constructive, deterministic solution can be obtained by sequentially examining every number in the interval from 2 to n

. If a factor is discovered, then n is composite.

A non-deterministic computation begins by arbitrarily choosing a value in the designated range (that is, in 2 to n

interval). A single division determines whether the guess is a factor. If n is

composite, one of the non-deterministic choices will produce a factor and that computation returns the affirmative response.

A string is accepted by a non-deterministic Turing Machine if at least one computation terminates in an accepting state or final state. The acceptance of the string is unaffected by the existence of other computations that halt in non-accepting states or that do not halt at all.

The worst case performance of the algorithm, however, measures the efficiency over all computations.

Def. (Time complexity of a non-deterministic Turing Machine)

Let M be a non-deterministic Turing Machine. The time complexity of M is the function

M : N Ntc such that M ( )tc n is the maximum number of transitions processed by a computation, employing any choice of transitions, of an input string of length n.

Note-1: While computing the time complexity, the non-deterministic analysis must consider all possible computations (using the transition function ) for an input string.

Note-2: The definition of time complexity assumes that every computation of the non-deterministic Turing Machine M terminates.

Note-3: non-deterministic computations utilizing a guess-and-check strategy are generally simpler than their deterministic counterparts. The simplicity reduces the number of transitions required for a single computation.

Page 33: theory of computation notes

SPACE COMPLEXITY

Here we analyze the space required by a computation. In high level algorithmic problem solving, the amount of time and memory required by a program are related. The Turing Machine used to analyze space complexity is assumed to be deterministic here.

Tape-1 which contains the input is read-only. With an input string of length n, the head on the input tape must remain within tape positions 0 through (n + 1). The Turing Machine reads the input tape but performs its work on the remaining tapes, and the space occupied by the input is not included in the complexity analysis. The space complexity measures the amount of space on the work tapes used by a computation.

Def. (Space complexity of a Turing Machine)

Let M be a k-tape Turing Machine designed for space complexity analysis. The space complexity of M is the function M : N Nsc such that M ( )sc n is the maximum number of tape squares read on tapes 2,3,…..,k by a computation of M when initiated with an input string of length n.

Note: We assume that the computations of the Turing Machine terminate for every input string, for the purpose of measuring space complexity.

Page 34: theory of computation notes

For example, we can design a 3-tape Turing Machine M that accepts the palindromes over ,a b with M ( ) log( )sc n O n .

Theorem: Let M be a k-tape Turing Machine with time complexity M ( ) ( )tc n f n . Then

M ( ) ( 1). ( )sc n k f n .

Proof: The maximum amount of tape is read when each transition of M moves the R/W heads on tapes 2,3,…..,k to the right. Hence, in this case, each head on a work tape reads at most f(n) different squares. Therefore, the maximum number of squares read is ( 1). ( )k f n and so

M ( ) ( 1). ( )sc n k f n .

The preceding theorem shows that the time complexity of a Turing Machine provides an upper bound on the space required. However, obtaining the restriction on time complexity imposed by a known space bound is very complicated.

Def. (Tractable Problem)

A decision problem is considered to be tractable if there is a deterministic Turing Machine that solvesthe problem whose computations are polynomially bounded. Problems that are solvable not only in principle, but also in practice, are tractable problems.

Def. (Intractable Problems)

A decision problem for which no polynomial algorithm is known and for which it is conjectured that no such algorithms exists, is called an intractable problem. Problems that may be solvable in principle, but are not solvable in practice are intractable problems.

Note-1: Functions that grow faster than any polynomial are deemed to grow too fast. Intractable problems are problems that in principle can be solved, but in practice take so much time that computers are useless for all but very small instances of the problem. Intractable problems require more than any polynomial running time.

Note-2: Generally, we think of problems that are solvable by polynomial time algorithms as being tractable, or easy, and problems that require super-polynomial time as being intractable or hard.

Definition of class P:

A language L is decidable in polynomial time if there is a standard Turing Machine M that accepts L with M ( ) ( )rtc n O n , where r is a natural number independent of n. The family of

languages decidable in polynomial time is denoted by P.

Page 35: theory of computation notes

Definition of class NP:

A language L is said to be accepted in non-deterministic polynomial time if there exists a non-deterministic Turing Machine M that accepts L with M ( ) ( )rtc n O n , where r is a natural number independent of n. The family of languages accepted in non-deterministic polynomial time is denoted by NP.

Note-1: Informally, a decision problem belongs to a class P if there is a polynomial algorithm to solve every instance of the problem. For example, the linear programming problem (LPP) is a member of the class P (Khachiyan’s ellipsoid algorithm).

Again, for instance, the Minimum Weight Spanning Tree (MWST) problem is in class P (Kruskal’s algorithm). The MWST is – “Given a weighted graph G and limit w, does G have a spanning tree of weight w or less?”

Many of the sorting algorithms in data structures are also in P (for example, quicksort ( 2( )O n ) and heapsort( ( log )O n n ))

Note-2: P ⊆ NP since an ordinary Turing Machine can be viewed as a non-deterministic Turing Machine.

Note-3: Whether every problem that can be solved in polynomial time by a non-deterministic algorithm can also be solved deterministically in polynomial time, is currently the outstanding open question in theoretical computer science. Nobody knows whether NP ⊆ P or not, and whether P = NP.

Def. (Polynomial Reducibility)

Let Q and L be languages over alphabets 1 and 2 respectively. We say that Q is reducible to L

in polynomial time, if there is a polynomial time computable function * *1 2:f such that

u Q if and only if ( )f u L .

Note-1: The fact that Q is reducible to L in polynomial time is denoted by pQ L .

Note-2: A reduction of Q to L transforms the problem of accepting Q to that of accepting L. Let F be a Turing Machine that computes the function f. If L is accepted by machine M then Q is accepted by a Turing Machine that

(i) runs F on an input string *1u

(ii) runs M on f(u)

Page 36: theory of computation notes

The resulting string f(u) is accepted by M if and only if u Q .

Theorem: Let Q be reducible to L in polynomial time and let L∈P. Then Q∈P.

Proof: Let F denote the machine that computes the reduction and M be the machine that recognizes L.

Q is accepted by a machine that sequentially runs F and M.

The time complexities Ftc and Mtc combine to produce an upper bound on the number of transitions on the composite machine.

The computation of F with input string u generates the string ( )f u L which provides input to M.

If the input string u Q has length n, then the length of f(u) cannot exceed the maximum of n and F ( )tc n . If F ( )rtc O n and M ( )ttc O n , then time complexity of the composite machine is

F M F( ) ( ) ( ) ( ) ( )r rt rttc n tc tc n O n O n O n

Since Q is accepted by the composite machine having time complexity ( )rtO n therefore Q∈P.

Def. (NP -Hard Language)

A language L is called NP-Hard if for every Q∈NP we have pQ L (that is, Q is reducible to

L in polynomial time).

Def. (NP -Complete Language)

A language L is called NP –Complete if

(1) L∈NP (2) L is NP-Hard

Theorem: If there is an NP –Complete language L such that L∈P then NP = P.

Proof: Assume that L is an NP –Complete language that is accepted in polynomial time by a deterministic Turing Machine.

Let Q be any language in NP. Since L is NP-Hard, so there is a polynomial time reduction of Q to L (that is, pQ L ). But L∈P. Hence, by previous theorem, Q∈P also. Thus NP ⊆ P.

Also P ⊆ NP. Therefore, NP = P.

Page 37: theory of computation notes

Some NP –Complete Problems:

(1) The Satisfiability Problem (SAT-Problem) is NP –Complete. The SAT-Problem is the problem of deciding if a propositional formula in conjunctive normal form (CNF) is satisfied by some truth assignment.

(2) The Vertex Cover Problem is NP –Complete. Let G= (N, A) be an undirected graph. A subset VC of N is said to be a vertex cover of G if for every arc [u, v] in A at least one of u or v is in VC. The vertex cover problem is: For an undirected graph G and an integer k, is there a vertex cover of G containing k vertices?

(3) The Hamiltonian Circuit Problem is NP –Complete. Let G be a directed graph with n vertices numbered 1 to n. An arc from vertex i to vertex j is denoted by ordered pair [i, j] . A Hamiltonian circuit is a path 0 1, ,....., ni i i in G that satisfies (i) 0 ni i (ii) j ki i

whenever j k and 0 ,j k n . That is, a Hamiltonian circuit is a path that visits every vertex exactly once and terminates at its starting point. A Hamiltonian circuit is also called a tour. Since each vertex is contained in a tour, we assume that every tour begins and ends at vertex 1i . The Hamiltonian circuit problem is to determine whether a directed graph has a tour.

*****