chapter 7 and 8
chapter 7 and 8
Computability
and complexity theory
Computability Theory
Computability theory answers:
What problems can computers solve?
For example,
if the time complexity is 3n + 5, then doubling the length of the string roughly
doubles the worst-case runtime.
If the time complexity is 2n – n2 , since 2n grows much more quickly than n2 , for
large values of n, increasing the size of the input by 1 doubles the worst-case
running time
Big-O Notation
Examples:
4n + 4 = O(n)
137n + 271 = O(n)
n 2 + 3n + 4 = O(n2)
2 n + n 3 = O(2n)
137 = O(1)
n 2 log n + log5 n = O(n2 log n)
Big-O Notation, Formally
Let f : ℕ → ℕ and g : ℕ → ℕ.
Then f(n) = O(g(n)) iff there exist constants c ℝ
and n0 ℕ such that
For any n ≥ n0 , f(n) ≤ cg(n)
nO(1).
• NP = the set of decision problems solvable in
nondeterministic polynomial time.
Decision Problems
• The output of these problems is a YES or NO answer.
• Example: is N prime? Do sequences x and y have common subsequences of length>k?
• For many problems there is an associated decision problem.
15
NP
16
NP
17
NP
18
Maximum Clique
7
17 8
16 1 9
6 2
15 10
5 3
4
14 11
13 12
19
Maximum Clique
7
17 8
16 1 9
6 2
15 10
5 3
4
14 11
13 12
1
10 7
5 2
4 3
9 8
21
3-Coloring
1
10 7
5 2
4 3
9 8
1 5 2 4 3 7 1 5 9 4 3 8 10 2 6
1 5 2 4 3 7 ?
Given n numbers, can they be partitioned into 2 sets such
that the sums of the numbers in the sets are equal
23
Partition Problem
1 5 2 4 3 7 1 5 9 4 3 8 10 2 6
1 5 2 4 3 7 ?
Given n numbers, can they be partitioned into 2 sets such
that the sums of the numbers in the sets are equal
Easy to verify given the two sets, so it is in NP.
24
P v NP
25
P v NP
Recall that for a decision problem in NP, if the answer is yes for
a given input then the “solution” can be verified efficiently
But can we compute the solution efficiently?
26
P v NP
Recall that for a decision problem in NP, if the answer is yes for
a given input then the “solution” can be verified efficiently
But can we compute the solution efficiently?
We don’t know! This isthe P =? NP question.
27
Hard Problems
?
One approach to settling P = NP: Identify the “hardest”
problems in NP and focus on solving them in poly-time
28
Hard Problems
?
One approach to settling P = NP: Identify the “hardest”
problems in NP and focus on solving them in poly-time
But how do we know which problems are hard?
29
Hard Problems
?
One approach to settling P = NP: Identify the “hardest”
problems in NP and focus on solving them in poly-time
But how do we know which problems are hard?
Idea: Reductions
30
Reductions
Input x to A
We can reduce problem A to problem B if we
can use a solution to B to solveA.
reduction f
f(x)
Algorithm for B
Output for A
31
Reductions
Input x to A
We can reduce problem A to problem B if we
can use a solution to B to solveA.
reduction f
Example: Problem A is finding the median of n
f(x) elements and Problem B is sorting n elements.
Algorithm for B
Output for A
32
Reductions
Input x to A
We can reduce problem A to problem B if we
can use a solution to B to solveA.
reduction f
Example: Problem A is finding the median of n
f(x) elements and Problem B is sorting n elements.
A reduces to B since we can take the input
Algorithm for B
to A, sort it using the solution to B, and
then recover the solution to A by looking at
the middle element in sorted order.
Output for A
33
Reductions cont.
34
Reductions cont.
35
Reductions cont.
36
Reduction Definition
Input to A
We need a more rigorous definition of a
reduction to identify the hardest problems in NP.
f (x)
Algorithm for B
Output for A
37
Reduction Definition
Input to A
We need a more rigorous definition of a reduction
to identify the hardest problems in NP.
f (x) We say Decision Problem A reduces to Decision
problem B if there is a function f mapping
inputs of A to inputs of B such that:
If x is a YES input for A, then f (x) is a YES
Algorithm for B input for B
IF x is a NO input for A, then f (x) is a NO
input for B
Output for A
38
Reduction Definition
Input to A
We need a more rigorous definition of a reduction
to identify the hardest problems in NP.
f (x) We say Decision Problem A reduces to Decision
problem B if there is a function f mapping
inputs of A to inputs of B such that:
If x is a YES input for A, then f (x) is a YES
Algorithm for B input for B
IF x is a NO input for A, then f (x) is a NO
input for B
Output for A The reduction is f itself.
39
Poly-Time Reductions
40
Poly-Time Reductions
41
Poly-Time Reduction Implications
42
Poly-Time Reduction Implications
43
Poly-Time Reduction Implications
44
Example
45
Example
46
Example
47
NP −Completeness Definition
48
NP −Completeness Definition
49
NP −Completeness Definition
50
Satisfiability
51
Satisfiability
52
Satisfiability
53
Satisfiability
54
Properties of Reductions
55
Properties of Reductions
56