CS 133 : Automata Theory and Computability Intractability

Nestine Hope S. Hernandez Algorithms and Complexity Laboratory Department of Computer Science University of the Philippines, Diliman [email protected]

Day 19

Time Complexity Intractability

Time Complexity The Class P The Class NP

Time Complexity The number of steps that an algorithm uses on a particular input may depend on several parameters.

Time Complexity The number of steps that an algorithm uses on a particular input may depend on several parameters. For simplicity, we compute the running time of an algorithm purely as a function of the length of the string representing the input and don't consider any other parameters.

Time Complexity The number of steps that an algorithm uses on a particular input may depend on several parameters. For simplicity, we compute the running time of an algorithm purely as a function of the length of the string representing the input and don't consider any other parameters.

Denition Let

M

be a deterministic Turing machine that halts on all inputs.

The running time or time complexity of where

f (n)

M

f : N → N, M uses on any M , we say that M

is the function

is the maximum number of steps that

n. If f (n) is the running time of f (n) and that M is an f (n) time Turing machine. we use n to represent the length of the input.

input of length runs in time Customarily

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it.

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs.

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs. Example:

f1 (n) = 6n3 + 2n2 + 20n + 45

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs. Example:

f1 (n) = 6n3 + 2n2 + 20n + 45 ⇒ f1 (n) = O(n3 ), the asymptotic

notation or big-O notation

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs. Example:

f1 (n) = 6n3 + 2n2 + 20n + 45 ⇒ f1 (n) = O(n3 ), the asymptotic

notation or big-O notation

g be functions f, g : N → R+ . Say that f (n) = O(g(n)) if positive integers c for every integer n ≥ n0 , f (n) ≤ c g(n). Let

f

and

and

n0

exist such that

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs. Example:

f1 (n) = 6n3 + 2n2 + 20n + 45 ⇒ f1 (n) = O(n3 ), the asymptotic

notation or big-O notation

g be functions f, g : N → R+ . Say that f (n) = O(g(n)) if positive integers c for every integer n ≥ n0 , f (n) ≤ c g(n). Let

f

and

f2 (n) = 3n log2 n + 5nlog2 log2 n + 2

and

n0

exist such that

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs. Example:

f1 (n) = 6n3 + 2n2 + 20n + 45 ⇒ f1 (n) = O(n3 ), the asymptotic

notation or big-O notation

g be functions f, g : N → R+ . Say that f (n) = O(g(n)) if positive integers c for every integer n ≥ n0 , f (n) ≤ c g(n). Let

f

and

and

n0

exist such that

f2 (n) = 3n log2 n + 5nlog2 log2 n + 2 ⇒ f2 (n) = O(n log n) f3 (n) = O(n2 ) + O(n)

Time Complexity Big-O Notation Because the exact running time of an algorithm often is a complex expression, we usually just estimate it. We consider only the highest order term of the expression for the running time of the algorithm, disregarding both the coecient of that term and any lower order terms, because the highest order term dominates the other terms on large inputs. Example:

f1 (n) = 6n3 + 2n2 + 20n + 45 ⇒ f1 (n) = O(n3 ), the asymptotic

notation or big-O notation

g be functions f, g : N → R+ . Say that f (n) = O(g(n)) if positive integers c for every integer n ≥ n0 , f (n) ≤ c g(n). Let

f

and

and

n0

exist such that

f2 (n) = 3n log2 n + 5nlog2 log2 n + 2 ⇒ f2 (n) = O(n log n) f3 (n) = O(n2 ) + O(n) ⇒ f3 (n) = O(n2 )

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0}

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept.

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept. stage 1:

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept. stage 1:

2n = O(n)

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept. stage 1: stage 2:

2n = O(n)

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept. stage 1: stage 2:

2n = O(n) n 2 2 O(n) = O(n )

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept. stage 1: stage 2: stage 3:

2n = O(n) n 2 2 O(n) = O(n )

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept. stage 1: stage 2: stage 3:

2n = O(n) n 2 2 O(n) = O(n ) O(n)

Time Complexity Analyzing Algorithms

k k

A = {0 1 | k ≥ 0} M1 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat if both 0s and 1s remain on the tape:

B

Scan across the tape, crossing o a single 0 and a single 1.

3. If 0s still remain after all the 1s have been crossed o, or if 1s still remain after all the 0s have been crossed o, reject. Otherwise, if neither 0s nor 1s remain on the tape, accept.

2n = O(n) n 2 2 O(n) = O(n ) stage 3: O(n) Thus the total time of M1 on an O(n) + O(n2 ) + O(n) = O(n2 ). stage 1: stage 2:

input of length

n

is

Time Complexity

Denition Let

t : N → R+

be a function.

Dene the time complexity class,

T IM E(t(n)), to be the collection of O(t(n)) time Turing machine.

all languages that are decidable by an

Time Complexity

Denition Let

t : N → R+

be a function.

Dene the time complexity class,

T IM E(t(n)), to be the collection of O(t(n)) time Turing machine.

all languages that are decidable by an

A ∈ T IM E(n2 ) because M1 decides A T IM E(n ) contains all languages that can be

Hence, in the preceding slide, in time

2

O(n ) and O(n2 ).

decided on

2

Time Complexity

Denition Let

t : N → R+

be a function.

Dene the time complexity class,

T IM E(t(n)), to be the collection of O(t(n)) time Turing machine.

all languages that are decidable by an

A ∈ T IM E(n2 ) because M1 decides A T IM E(n ) contains all languages that can be

Hence, in the preceding slide, in time

2

O(n ) and O(n2 ).

2

decided on

Is there a machine that decides

A

asymptotically more quickly?

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject.

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject. stage 1:

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject. stage 1:

O(n)

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject. stage 1: stage 2:

O(n)

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject. stage 1: stage 2:

O(n) (1 + log2 n)O(n) = O(n log n)

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject. stage 1: stage 2: stage 3:

O(n) (1 + log2 n)O(n) = O(n log n)

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject. stage 1: stage 2: stage 3:

O(n) (1 + log2 n)O(n) = O(n log n) O(n)

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject.

O(n) (1 + log2 n)O(n) = O(n log n) stage 3: O(n) Thus the total time of M1 on an input of O(n) + O(n log n) + O(n) = O(n log n). stage 1:

stage 2:

length

n

is

Time Complexity

M2 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Repeat as long as some 0s and some 1s remain on the tape:

B

Scan across the tape, checking whether the total number of 0s

and 1s remaining is even or odd. If it is odd, reject.

B

Scan again across the tape, crossing o every other 0 starting

with the rst 0, and then crossing o every other 1 starting with the rst 1. 3. If no 0s and no 1s remain on the tape, accept. Otherwise, reject.

O(n) (1 + log2 n)O(n) = O(n log n) stage 3: O(n) Thus the total time of M1 on an input of O(n) + O(n log n) + O(n) = O(n log n). stage 1:

stage 2:

Hence,

A ∈ T IM E(n log n)

length

n

is

Time Complexity

M3 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Scan across the 0s on tape 1 until the rst 1. At the same time, copy the 0s onto tape 2. 3. Scan across the 1s on tape 1 until the end of the input. For each 1 read on tape 1, cross o a 0 on tape 2. If all 0s are crossed o before all the 1s are read, reject. 4. If all the 0s have now been crossed o, accept. if any 0s remain, reject.

Time Complexity

M3 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Scan across the 0s on tape 1 until the rst 1. At the same time, copy the 0s onto tape 2. 3. Scan across the 1s on tape 1 until the end of the input. For each 1 read on tape 1, cross o a 0 on tape 2. If all 0s are crossed o before all the 1s are read, reject. 4. If all the 0s have now been crossed o, accept. if any 0s remain, reject.

A O(n).

Hence, the time complexity of and on a 2-tape TM it is

on a single-tape TM is

O(n log n)

Time Complexity

M3 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Scan across the 0s on tape 1 until the rst 1. At the same time, copy the 0s onto tape 2. 3. Scan across the 1s on tape 1 until the end of the input. For each 1 read on tape 1, cross o a 0 on tape 2. If all 0s are crossed o before all the 1s are read, reject. 4. If all the 0s have now been crossed o, accept. if any 0s remain, reject.

A O(n).

Hence, the time complexity of and on a 2-tape TM it is

on a single-tape TM is

O(n log n)

In computability theory, the Church-Turing thesis implies that all reasonable models of computation are equivalent, that is, they all decide the same class of languages.

Time Complexity

M3 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Scan across the 0s on tape 1 until the rst 1. At the same time, copy the 0s onto tape 2. 3. Scan across the 1s on tape 1 until the end of the input. For each 1 read on tape 1, cross o a 0 on tape 2. If all 0s are crossed o before all the 1s are read, reject. 4. If all the 0s have now been crossed o, accept. if any 0s remain, reject.

A O(n).

Hence, the time complexity of and on a 2-tape TM it is

on a single-tape TM is

O(n log n)

In computability theory, the Church-Turing thesis implies that all reasonable models of computation are equivalent, that is, they all decide the same class of languages. In complexity theory, the choice of model aects the time complexity of languages.

Time Complexity

M3 =

On input string

w:

1. Scan across the tape and reject if a 0 is found to the right of a 1. 2. Scan across the 0s on tape 1 until the rst 1. At the same time, copy the 0s onto tape 2. 3. Scan across the 1s on tape 1 until the end of the input. For each 1 read on tape 1, cross o a 0 on tape 2. If all 0s are crossed o before all the 1s are read, reject. 4. If all the 0s have now been crossed o, accept. if any 0s remain, reject.

A O(n).

Hence, the time complexity of and on a 2-tape TM it is

on a single-tape TM is

O(n log n)

In computability theory, the Church-Turing thesis implies that all reasonable models of computation are equivalent, that is, they all decide the same class of languages. In complexity theory, the choice of model aects the time complexity of languages. In complexity theory, we classify computational problems according to their time complexity. But with which model do we measure time?

Time Complexity Complexity Relationships among models

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time multitape Turing machine has an equivalent O(t2 (n)) time single-tape TM.

Time Complexity Complexity Relationships among models

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time multitape Turing machine has an equivalent O(t2 (n)) time single-tape TM.

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time nondeterministic single-tape Turing machine has an equivalent 2O(t(n)) time deterministic single-tape TM.

Time Complexity Complexity Relationships among models

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time multitape Turing machine has an equivalent O(t2 (n)) time single-tape TM.

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time nondeterministic single-tape Turing machine has an equivalent 2O(t(n)) time deterministic single-tape TM. The theorems above demonstrated at most a square or polynomial dierence between the time complexity measures on deterministic single-tape and multitape TMs

Time Complexity Complexity Relationships among models

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time multitape Turing machine has an equivalent O(t2 (n)) time single-tape TM.

Theorem

Let t(n) be a function, where t(n) ≥ n. Then every t(n) time nondeterministic single-tape Turing machine has an equivalent 2O(t(n)) time deterministic single-tape TM. The theorems above demonstrated at most a square or polynomial dierence between the time complexity measures on deterministic single-tape and multitape TMs and at most an exponential dierence between the time complexity of problems on deterministic and nondeterministic TMs.

Time Complexity

From here on we focus on aspects of time complexity theory that are unaected by polynomial dierences in running time. We consider such dierences to be insignicant and ignore them. The decision to disregard polynomial dierences doesn't imply that we consider such dierences unimportant. On the contrary, we certainly do consider the dierence between time

n

and time

n3

to be an important one.

But some questions that do not depend on polynomial dierences are important too.

Time Complexity

Denition P

is the class of language that are decidable in polynomial time on a

deterministic single-tape TM.

P=

[ k

T IM E(nk )

Time Complexity

Denition P

is the class of language that are decidable in polynomial time on a

deterministic single-tape TM.

P=

[

T IM E(nk )

k

1.

P

is invariant for all models of computation that are

polynomially equivalent to the deterministic single-tape TM, and 2.

P

roughly corresponds to the class of problems that are

realistically solvable on a computer.

Time Complexity Examples of Problems in

P

Time Complexity Examples of Problems in

P AT H = {< G, s, t > | G is a directed graph

P

that has a directed path from

s

to

t.}

Time Complexity Examples of Problems in

P AT H = {< G, s, t > | G is a directed graph

P

that has a directed path from

P AT H ∈ P

s

to

t.}

Time Complexity Examples of Problems in

P AT H = {< G, s, t > | G is a directed graph

P

that has a directed path from

s

to

t.}

P AT H ∈ P M = On and t:

input

< G, s, t >

1. Place a mark on node

where

G

is a directed graph with nodes

s

s.

2. Repeat the until no addtl nodes are marked:

B

Scan all the edges of

marked node 3. If

t

a

G.

If an edge

to an unmarked node

(a, b) is found going b, mark node b.

is marked, accept. Otherwise, reject.

from a

Time Complexity Examples of Problems in

P

Time Complexity Examples of Problems in

RELP RIM E = {< x, y > | x

and

y

P

are relatively prime.}

Time Complexity Examples of Problems in

RELP RIM E = {< x, y > | x

and

y

P

are relatively prime.}

RELP RIM E ∈ P

Time Complexity Examples of Problems in

RELP RIM E = {< x, y > | x

and

y

P

are relatively prime.}

RELP RIM E ∈ P E=

On input

< x, y >

1. Repeat until

B

Exchange

2. Output

x.

where

y = 0: B x and y .

x

and

Assign

y

are natural numbers in binary:

x ← x mod y .

Time Complexity Examples of Problems in

RELP RIM E = {< x, y > | x

and

y

P

are relatively prime.}

RELP RIM E ∈ P E=

< x, y >

On input

1. Repeat until

B

Exchange

2. Output

R=

where

y = 0: B x and y .

x

and

Assign

y

are natural numbers in binary:

x ← x mod y .

x.

On input

1. Run E on

< x, y >

where

x

and

y

are natural numbers in binary:

< x, y >.

2. If the result is 1, accept. Otherwise, reject.

Time Complexity

There are problems, including many interesting and useful ones, wherein polynomial time algorithms that solve them aren't known to exist.

Time Complexity

There are problems, including many interesting and useful ones, wherein polynomial time algorithms that solve them aren't known to exist. Why have we been unsuccessful in nding polynomial time algorithms for these problems?

Time Complexity

There are problems, including many interesting and useful ones, wherein polynomial time algorithms that solve them aren't known to exist. Why have we been unsuccessful in nding polynomial time algorithms for these problems? We don't know.

Time Complexity

There are problems, including many interesting and useful ones, wherein polynomial time algorithms that solve them aren't known to exist. Why have we been unsuccessful in nding polynomial time algorithms for these problems? We don't know. Perhaps these problems have, as yet undiscovered, polynomial time algorithms that rest on unknown principles.

Time Complexity

There are problems, including many interesting and useful ones, wherein polynomial time algorithms that solve them aren't known to exist. Why have we been unsuccessful in nding polynomial time algorithms for these problems? We don't know. Perhaps these problems have, as yet undiscovered, polynomial time algorithms that rest on unknown principles. Or possibly some of these problems simply cannot be solved in polynomial time.

Time Complexity

Time Complexity

HAM P AT H = {< G, s, t > | G is a directed graph with a

Hamiltonian path from

s

to

t.}

Time Complexity

HAM P AT H = {< G, s, t > | G is a directed graph with a

Hamiltonian path from

s

to

t.}

We can easily obtain an exponential time algorithm for this problem by modifying the algorithm for

P AT H .

We need only add a check to

verify that the potential path is Hamiltonian.

Time Complexity

HAM P AT H = {< G, s, t > | G is a directed graph with a

Hamiltonian path from

s

to

t.}

We can easily obtain an exponential time algorithm for this problem by modifying the algorithm for

P AT H .

We need only add a check to

verify that the potential path is Hamiltonian. No one knows whether

HAM P AT H

is solvable in polynomial time.

Time Complexity

HAM P AT H = {< G, s, t > | G is a directed graph with a

Hamiltonian path from

s

to

t.}

We can easily obtain an exponential time algorithm for this problem by modifying the algorithm for

P AT H .

We need only add a check to

verify that the potential path is Hamiltonian. No one knows whether

HAM P AT H

But the HAMPATH problem is

is solvable in polynomial time.

polynomial veriable.

Time Complexity

HAM P AT H = {< G, s, t > | G is a directed graph with a

Hamiltonian path from

s

to

t.}

We can easily obtain an exponential time algorithm for this problem by modifying the algorithm for

P AT H .

We need only add a check to

verify that the potential path is Hamiltonian. No one knows whether

HAM P AT H

But the HAMPATH problem is

is solvable in polynomial time.

polynomial veriable.

That is, even though we don't know of a fast way to determine whether a graph contains a Hamiltonian path, if such a path were discovered somehow, we could easily convince someone else of its existence, simply by presenting it.

Time Complexity

Denition A verier for a language A is an algorithm V, where

A = {w | V

accepts

< w, c >

for some string

c}. w,

so

a polynomial time verier runs in polynomial time in the length of

w.

We measure the time of a verier only in terms of the length of

A language A is polynomially veriable if it has a polynomial time verier.

Time Complexity

Denition A verier for a language A is an algorithm V, where

A = {w | V

accepts

< w, c >

for some string

c}. w,

so

a polynomial time verier runs in polynomial time in the length of

w.

We measure the time of a verier only in terms of the length of

A language A is polynomially veriable if it has a polynomial time verier.

Denition NP

is the class of languages that have polynomial time veriers.

Time Complexity

Theorem

A language is in NP i it is decided by some nondeterministic polynomial time TM.

Time Complexity

Theorem

A language is in NP i it is decided by some nondeterministic polynomial time TM. The following nondeterministic TM decides the

HAM P AT H

problem

in nondeterministic polynomial time.

N1 = On and t:

input

< G, s, t >

1. Write a list of nodes in

G.

m

where

numbers

G

is a directed graph with nodes

p1 , · · · , pm ,

where

m

is the number of

Each number in the list is nondeterministically

selected to be between

1

and

m.

2. Check for repetitions in the list. If any are found, reject. 3. Check whether

s = p1

t = pm .

i between 1 and m − 1, G. If any are not, reject.

4. For each edge of

and

passed, so accept.

if either fail, reject.

check whether

s

(pi , pi+1 )

is an

Otherwise, all tests have been

Time Complexity

Denition N T IM E(t(n)) = {L|L is a language

decided by a

Corollary NP =

S

k

N T IM E(nk )

O(t(n))

time nondeterministic TM}.

Time Complexity Examples of Problems in NP

CLIQU E = {< G, k > |G

is an undirected graph with a

k -clique}

Time Complexity Examples of Problems in NP

CLIQU E = {< G, k > |G

CLIQUE is in NP.

is an undirected graph with a

k -clique}

Time Complexity Examples of Problems in NP

CLIQU E = {< G, k > |G

CLIQUE is in NP.

is an undirected graph with a

k -clique}

Time Complexity Examples of Problems in NP

CLIQU E = {< G, k > |G

CLIQUE is in NP.

is an undirected graph with a

k -clique}

Time Complexity Examples of Problems in NP

SU BSET SU M = {< S, t > |S = {x1P , · · · , xk } and {y1 , · · · , yl } ⊆ {x1 , · · · , xk }, we have yi = t}.

SU BSET SU M

is in NP.

for some

Time Complexity Examples of Problems in NP

SU BSET SU M = {< S, t > |S = {x1P , · · · , xk } and {y1 , · · · , yl } ⊆ {x1 , · · · , xk }, we have yi = t}.

SU BSET SU M

is in NP.

for some

Time Complexity Examples of Problems in NP

SU BSET SU M = {< S, t > |S = {x1P , · · · , xk } and {y1 , · · · , yl } ⊆ {x1 , · · · , xk }, we have yi = t}.

SU BSET SU M

is in NP.

for some

Time Complexity

P = NP ?

Time Complexity

Questions? See you next meeting!