np-completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · why this...
TRANSCRIPT
![Page 1: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/1.jpg)
NP-CompletenessPart One
![Page 2: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/2.jpg)
Recap from Last Time
![Page 3: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/3.jpg)
RegularLanguages CFLs
All Languages
R RE
![Page 4: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/4.jpg)
All Languages
RERegularLanguages CFLs R
![Page 5: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/5.jpg)
Undecidable Languages
RegularLanguages CFLs R
EfficientlyDecidable
Languages
![Page 6: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/6.jpg)
The Cobham-Edmonds Thesis
A language L can be decided efficiently ifthere is a TM that decides it in polynomial time.
Equivalently, L can be decided efficiently ifit can be decided in time O(nk) for some k ∈ ℕ.
Like the Church-Turing thesis, this is not a theorem!
It's an assumption about the nature of efficient computation, and it is
somewhat controversial.
Like the Church-Turing thesis, this is not a theorem!
It's an assumption about the nature of efficient computation, and it is
somewhat controversial.
![Page 7: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/7.jpg)
The Complexity Class P
● The complexity class P (for polynomial time) contains all problems that can be solved in polynomial time.
● Formally:
P = { L | There is a polynomial-time decider for L }
● Assuming the Cobham-Edmonds thesis, a language is in P if it can be decided efficiently.
![Page 8: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/8.jpg)
New Stuff!
![Page 9: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/9.jpg)
Examples of Problems in P
● All regular languages are in P.● All have linear-time TMs.
● All CFLs are in P.● Requires a more nuanced argument (the
CYK algorithm or Earley's algorithm.)
● And a ton of other problems are in P as well.● Curious? Take CS161!
![Page 10: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/10.jpg)
Undecidable Languages
RegularLanguages CFLs R
EfficientlyDecidable
Languages
![Page 11: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/11.jpg)
Undecidable Languages
RegularLanguages CFLs RP
![Page 12: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/12.jpg)
What can't you do in polynomial time?
![Page 13: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/13.jpg)
start
end
How many simple paths are there from the start node to the end
node?
How many simple paths are there from the start node to the end
node?
![Page 14: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/14.jpg)
, , ,
How many subsets of this set are there?
How many subsets of this set are there?
![Page 15: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/15.jpg)
An Interesting Observation
● There are (at least) exponentially many objects of each of the preceding types.
● However, each of those objects is not very large.● Each simple path has length no longer than the
number of nodes in the graph.● Each subset of a set has no more elements than
the original set.
● This brings us to our next topic...
![Page 16: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/16.jpg)
NPN P
![Page 17: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/17.jpg)
What if you need to search a large space for a single object?
![Page 18: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/18.jpg)
Verifiers – Again
3
6
8
1
5
1
7
7
5
2
3
4
1
2
4
6
3
1
8
3
5
7
1
9
8
5
7
5
2
2
7
9
4
8
Does this Sudoku problem have a solution?
![Page 19: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/19.jpg)
Verifiers – Again
2
4
3
6
7
8
1
5
9
5
9
8
4
1
3
6
7
2
7
1
6
5
9
2
3
8
4
9
8
1
7
5
6
2
4
3
6
7
2
3
4
1
5
9
8
4
3
5
2
8
9
7
6
1
1
6
9
8
3
5
4
2
7
8
5
4
1
2
7
9
3
6
3
2
7
9
6
4
8
1
5
Does this Sudoku problem have a solution?
![Page 20: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/20.jpg)
4 3 11 9 7 13 5 6 1 12 2 8 0 109 3 11 4 2 13 5 6 1 12 7 8 0 10
Verifiers – Again
Is there an ascending subsequence of length at least 7?
![Page 21: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/21.jpg)
4 3 11 9 7 13 5 6 1 12 2 8 0 109 3 11 4 2 13 5 6 1 12 7 8 0 10
Verifiers – Again
Is there an ascending subsequence of length at least 7?
![Page 22: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/22.jpg)
Verifiers – Again
Is there a simple path that goes through every node exactly once?
![Page 23: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/23.jpg)
Verifiers – Again
Is there a simple path that goes through every node exactly once?
1
2
5
4
6
3
![Page 24: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/24.jpg)
Verifiers
● Recall that a verifier for L is a TM V such that● V halts on all inputs.● w ∈ L iff ∃c ∈ Σ*. V accepts ⟨w, c⟩.
![Page 25: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/25.jpg)
Polynomial-Time Verifiers
● A polynomial-time verifier for L is a TM V such that● V halts on all inputs.● w ∈ L iff ∃c ∈ Σ*. V accepts ⟨w, c⟩.● V's runtime is a polynomial in |w| (that is, V's
runtime is O(|w|k) for some integer k)
![Page 26: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/26.jpg)
The Complexity Class NP
● The complexity class NP (nondeterministic polynomial time) contains all problems that can be verified in polynomial time.
● Formally:
NP = { L | There is a polynomial-time verifier for L }
● The name NP comes from another way of characterizing NP. If you introduce nondeterministic Turing machines and appropriately define “polynomial time,” then NP is the set of problems that an NTM can solve in polynomial time.
![Page 27: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/27.jpg)
And now...
![Page 28: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/28.jpg)
The
Most Important Question
in
Theoretical Computer Science
![Page 29: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/29.jpg)
What is the connection between P and NP?
![Page 30: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/30.jpg)
P = { L | There is a polynomial-time decider for L }
NP = { L | There is a polynomial-time verifier for L }
P ⊆ NP
![Page 31: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/31.jpg)
P NP
Which Picture is Correct?
![Page 32: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/32.jpg)
P NP
Which Picture is Correct?
![Page 33: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/33.jpg)
Does P = NP?
![Page 34: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/34.jpg)
P ≟ NP
● The P ≟ NP question is the most important question in theoretical computer science.
● With the verifier definition of NP, one way of phrasing this question is
If a solution to a problem can be checked efficiently,can that problem be solved efficiently?
● An answer either way will give fundamental insights into the nature of computation.
![Page 35: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/35.jpg)
Why This Matters
● The following problems are known to be efficiently verifiable, but have no known efficient solutions:
● Determining whether an electrical grid can be built to link up some number of houses for some price (Steiner tree problem).
● Determining whether a simple DNA strand exists that multiple gene sequences could be a part of (shortest common supersequence).
● Determining the best way to assign hardware resources in a compiler (optimal register allocation).
● Determining the best way to distribute tasks to multiple workers to minimize completion time (job scheduling).
● And many more.
● If P = NP, all of these problems have efficient solutions.
● If P ≠ NP, none of these problems have efficient solutions.
![Page 36: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/36.jpg)
Why This Matters
● If P = NP:● A huge number of seemingly difficult problems
could be solved efficiently.● Our capacity to solve many problems will scale
well with the size of the problems we want to solve.
● If P ≠ NP:● Enormous computational power would be required
to solve many seemingly easy tasks.● Our capacity to solve problems will fail to keep up
with our curiosity.
![Page 37: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/37.jpg)
What We Know
● Resolving P ≟ NP has proven extremely difficult.
● In the past 44 years:● Not a single correct proof either way has been
found.● Many types of proofs have been shown to be
insufficiently powerful to determine whether P ≟ NP.
● A majority of computer scientists believe P ≠ NP, but this isn't a large majority.
● Interesting read: Interviews with leading thinkers about P ≟ NP:
● http://web.ing.puc.cl/~jabaier/iic2212/poll-1.pdf
![Page 38: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/38.jpg)
The Million-Dollar Question
The Clay Mathematics Institute has offered a $1,000,000 prize to anyone who proves
or disproves P = NP.
![Page 39: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/39.jpg)
The Million-Dollar Question
The Clay Mathematics Institute has offered a $1,000,000 prize to anyone who proves
or disproves P = NP.
![Page 40: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/40.jpg)
Time-Out for Announcements!
![Page 41: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/41.jpg)
Please evaluate this course in Axess.
Your feedback does make a difference.
![Page 42: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/42.jpg)
Problem Set Nine
● Problem Set Nine is due this Friday at 3:00PM.● No late days may be used – this is university
policy. Sorry about that!● We hope that the later questions help give
you some review for the final exam.
● Have questions? Stop by office hours or ask on Piazza!
![Page 43: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/43.jpg)
Extra Practice Problems
● We released three sets of cumulative review problems on Friday.
● Solutions will be available in the Gates building starting this afternoon – feel free to stop by to pick them up at your convenience!● SCPD students – you should get them over email later today.
● We've released two practice final exams to the course website. We strongly recommend blocking out three hours to work through them rather than just skimming over them. It's the best possible way to practice for the exam.
![Page 44: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/44.jpg)
Regrades Processed
● We've finished all the regrade requests for the first midterm exam.
● Regraded midterms will be available outside of class today. Feel free to pick them up from Gates if you aren't able to grab your exam today.
● SCPD students – if you emailed in a regrade request, we should get back to you by later this evening with feedback.
![Page 45: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/45.jpg)
Your Questions!
![Page 46: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/46.jpg)
“You said on Wednesday that you think there is nothing a human brain can do that
a Turing Machine can't do. However, it seems like humans are able to confirm whether a program is a secure voting
machine (among other things) by looking at the source code?”
Remember that the question is whether it's possible to confirm that any arbitrary program that purports to be a secure voting
machine is actually secure.
Remember that the question is whether it's possible to confirm that any arbitrary program that purports to be a secure voting
machine is actually secure.
![Page 47: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/47.jpg)
int main() { string input = getInput(); int n = countRs(input);
while (n > 1) { if (n % 2 == 0) n = n / 2; else n = 3 * n + 1; }
if (countRs(input) > countDs(input)) { accept(); } else { reject(); }}
This is a secure voting machine if and only if the Collatz Conjecture is true.
So no one knows whether thisis a secure voting machine!
This is a secure voting machine if and only if the Collatz Conjecture is true.
So no one knows whether thisis a secure voting machine!
![Page 48: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/48.jpg)
“Are you religious/do you think it's possible to balance discrete math and spirituality?
Realized after we concluded there are some problems mathematics can't solve
and I started thinking about the supernatural.”
Mathematical truth is not the same as religious truth, which is not the same as scientific truth, which
is not the same as legal truth, etc. Different systems judge truth in different ways and each gives
a different insight into the world.
Mathematical truth is not the same as religious truth, which is not the same as scientific truth, which
is not the same as legal truth, etc. Different systems judge truth in different ways and each gives
a different insight into the world.
![Page 49: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/49.jpg)
“What myth/false belief do you think is most widespread among Stanford
students? Care to dispel it?”
Please, please, please ask this question again on Wednesday. We're short on time today and I don't think I can answer this now, but I'd love to. So
please ask this again on Wednesday!
Please, please, please ask this question again on Wednesday. We're short on time today and I don't think I can answer this now, but I'd love to. So
please ask this again on Wednesday!
![Page 50: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/50.jpg)
Back to CS103!
![Page 51: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/51.jpg)
What do we know about P ≟ NP?
![Page 52: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/52.jpg)
Adapting our Techniques
![Page 53: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/53.jpg)
A Problem
● The R and RE languages correspond to problems that can be decided and verified period, without any time bounds.
● To reason about what's in R and what's in RE, we used two key techniques:● Universality: TMs can run other TMs as
subroutines.● Self-Reference: TMs can get their own source code.
● Why can't we just do that for P and NP?
![Page 54: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/54.jpg)
Theorem (Baker-Gill-Solovay): Any proof that purely relies on universality and self-reference cannot resolve P ≟ NP.
Proof: Take CS154!
![Page 55: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/55.jpg)
So how are we going toreason about P and NP?
![Page 56: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/56.jpg)
Reducibility
![Page 57: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/57.jpg)
Maximum Matching
● Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint.
● A maximum matching is a matching with the largest number of edges.
![Page 58: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/58.jpg)
Maximum Matching
● Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint.
● A maximum matching is a matching with the largest number of edges.
![Page 59: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/59.jpg)
Maximum Matching
● Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint.
● A maximum matching is a matching with the largest number of edges.
A matching, but not a maximum
matching.
A matching, but not a maximum
matching.
![Page 60: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/60.jpg)
Maximum Matching
● Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint.
● A maximum matching is a matching with the largest number of edges.
A maximum matching.
A maximum matching.
![Page 61: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/61.jpg)
Maximum Matching
● Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint.
● A maximum matching is a matching with the largest number of edges.
![Page 62: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/62.jpg)
Maximum Matching
● Given an undirected graph G, a matching in G is a set of edges such that no two edges share an endpoint.
● A maximum matching is a matching with the largest number of edges.
![Page 63: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/63.jpg)
Maximum Matching
● Jack Edmonds' paper “Paths, Trees, and Flowers” gives a polynomial-time algorithm for finding maximum matchings.● (This is the same Edmonds as in “Cobham-
Edmonds Thesis.”)
● Using this fact, what other problems can we solve?
![Page 64: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/64.jpg)
Domino Tiling
![Page 65: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/65.jpg)
Domino Tiling
![Page 66: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/66.jpg)
Domino Tiling
![Page 67: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/67.jpg)
Domino Tiling
![Page 68: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/68.jpg)
Domino Tiling
![Page 69: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/69.jpg)
Domino Tiling
![Page 70: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/70.jpg)
A Domino Tiling Reduction
● Let MATCHING be the language defined as follows:
MATCHING = { ⟨G, k⟩ | G is an undirected graph with a matching of size at least k }
● Theorem (Edmonds): MATCHING ∈ P.● Let DOMINO be this language:
DOMINO = { ⟨D, k⟩ | D is a grid and k nonoverlapping dominoes can be placed on D. }
● We'll use the fact that MATCHING ∈ P to prove that DOMINO ∈ P.
![Page 71: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/71.jpg)
Solving Domino Tiling
![Page 72: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/72.jpg)
Solving Domino Tiling
![Page 73: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/73.jpg)
Solving Domino Tiling
![Page 74: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/74.jpg)
Solving Domino Tiling
![Page 75: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/75.jpg)
Solving Domino Tiling
![Page 76: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/76.jpg)
Solving Domino Tiling
![Page 77: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/77.jpg)
Solving Domino Tiling
![Page 78: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/78.jpg)
Solving Domino Tiling
![Page 79: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/79.jpg)
In Pseudocode
boolean canPlaceDominos(Grid G, int k) {
return hasMatching(gridToGraph(G), k);
}
![Page 80: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/80.jpg)
Another Example
![Page 81: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/81.jpg)
Reachability
● Consider the following problem:
Given an directed graph G and nodes s and tin G, is there a path from s to t?
● As a formal language:
REACHABILITY = { ⟨G, s, t⟩ | G is a directed graph, s and t are nodes in G, and there's a path from s to t }
● Theorem: REACHABILITY ∈ P.● Given that we can solve the reachability problem in
polynomial time, what other problems can we solve in polynomial time?
![Page 82: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/82.jpg)
Converter Conundrums
● Suppose that you want to plug your laptop into a projector.
● Your laptop only has a VGA output, but the projector needs HDMI input.
● You have a box of connectors that convert various types of input into various types of output (for example, VGA to DVI, DVI to DisplayPort, etc.)
● Question: Can you plug your laptop into the projector?
![Page 83: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/83.jpg)
Converter Conundrums
ConnectorsRGB to USB
VGA to DisplayPortDB13W3 to CATV
DisplayPort to RGBDB13W3 to HDMIDVI to DB13W3S-Video to DVIFireWire to SDI
VGA to RGBDVI to DisplayPort
USB to S-VideoSDI to HDMI
ConnectorsRGB to USB
VGA to DisplayPortDB13W3 to CATV
DisplayPort to RGBDB13W3 to HDMIDVI to DB13W3S-Video to DVIFireWire to SDI
VGA to RGBDVI to DisplayPort
USB to S-VideoSDI to HDMI
![Page 84: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/84.jpg)
Converter Conundrums
ConnectorsRGB to USB
VGA to DisplayPortDB13W3 to CATV
DisplayPort to RGBDB13W3 to HDMIDVI to DB13W3S-Video to DVIFireWire to SDI
VGA to RGBDVI to DisplayPort
USB to S-VideoSDI to HDMI
ConnectorsRGB to USB
VGA to DisplayPortDB13W3 to CATV
DisplayPort to RGBDB13W3 to HDMIDVI to DB13W3S-Video to DVIFireWire to SDI
VGA to RGBDVI to DisplayPort
USB to S-VideoSDI to HDMI
VGA RGB USB
DisplayPort DB13W3 CATV
X DVIHDMI S-Video
FireWire SDI
![Page 85: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/85.jpg)
Converter Conundrums
VGA RGB USB
DisplayPort DB13W3 CATV
X DVIHDMI S-Video
FireWire SDI
![Page 86: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/86.jpg)
Converter Conundrums
VGA RGB USB
DisplayPort DB13W3 CATV
X DVIHDMI S-Video
FireWire SDI
![Page 87: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/87.jpg)
Converter Conundrums
VGA RGB USB
DisplayPort DB13W3 CATV
X DVIHDMI S-Video
FireWire SDI
![Page 88: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/88.jpg)
Converter Conundrums
VGA RGB USB
DisplayPort DB13W3 CATV
X DVIHDMI S-Video
FireWire SDI
ConnectorsRGB to USB
VGA to DisplayPortDB13W3 to CATV
DisplayPort to RGBDB13W3 to HDMIDVI to DB13W3S-Video to DVIFireWire to SDI
VGA to RGBDVI to DisplayPort
USB to S-VideoSDI to HDMI
ConnectorsRGB to USB
VGA to DisplayPortDB13W3 to CATV
DisplayPort to RGBDB13W3 to HDMIDVI to DB13W3S-Video to DVIFireWire to SDI
VGA to RGBDVI to DisplayPort
USB to S-VideoSDI to HDMI
![Page 89: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/89.jpg)
In Pseudocode
boolean canPlugIn(List<Plug> plugs) {
return isReachable(plugsToGraph(plugs), VGA, HDMI);
}
![Page 90: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/90.jpg)
A Commonality
● Each of the solutions to our previous problems had the following form:
boolean solveProblemA(input) { return solveProblemB(transform(input)); }
● Important observation: Assuming that we already have a solver for problem B, the only work done here is transforming the input to problem A into an input to problem B.
● All the “hard” work is done by the solver for B; we just turn one input into another.
![Page 91: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/91.jpg)
Mathematically Modeling this Idea
![Page 92: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/92.jpg)
Polynomial-Time Reductions
● Let A and B be languages.● A polynomial-time reduction from A to
B is a function f : Σ* → Σ* such that● ∀w ∈ Σ*. (w ∈ A ↔ f(w) ∈ B)● The function f can be computed in
polynomial time.
● What does this mean?
![Page 93: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/93.jpg)
Polynomial-Time Reductions
● If f is a polynomial-time reduction from A to B, then
∀w ∈ Σ*. (w ∈ A ↔ f(w) ∈ B) ● If you want to know whether w ∈ A,
you can instead ask whether f(w) ∈ B.● Every w ∈ A maps to some f(w) ∈ B.● Every w ∉ A maps to some f(w) ∉ B.
![Page 94: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/94.jpg)
Polynomial-Time Reductions
● If f is a polynomial-time reduction from A to B, then
∀w ∈ Σ*. (w ∈ A ↔ f(w) ∈ B)
Σ* Σ*
![Page 95: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/95.jpg)
Polynomial-Time Reductions
● If f is a polynomial-time reduction from A to B, then
∀w ∈ Σ*. (w ∈ A ↔ f(w) ∈ B)
A
A
Σ* Σ*
![Page 96: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/96.jpg)
Polynomial-Time Reductions
● If f is a polynomial-time reduction from A to B, then
∀w ∈ Σ*. (w ∈ A ↔ f(w) ∈ B)
A
A
Σ* Σ*
B
BΣ*
![Page 97: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/97.jpg)
Polynomial-Time Reductions
● If f is a polynomial-time reduction from A to B, then
∀w ∈ Σ*. (w ∈ A ↔ f(w) ∈ B)
A
A
Σ* Σ*
B
BΣ*
f(w)
f(w)
![Page 98: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/98.jpg)
Reductions, Programmatically
● Suppose we have a solver for problem B that's defined in terms of problem A in this specific way:
boolean solveProblemA(input) { return solveProblemB(transform(input)); }
● The reduction from A to B is the function transform in the above setup: it maps “yes” answers to A to “yes” answers to B and “no” answers to A to “no” answers to B.
![Page 99: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/99.jpg)
Reducibility among Problems
● Suppose that A and B are languages where there's a polynomial-time reduction from A to B.
● We'll denote this by writing
A ≤p B
● You can read this aloud as “A polynomial-time reduces to B” or “A poly-time reduces to B.”
![Page 100: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/100.jpg)
Two Key Theorems
● Theorem 1: If A ≤p B and B ∈ P, then A ∈ P.
● Theorem 2: If A ≤p B and B ∈ NP, then A ∈ NP.
● Intuitively, if A ≤p B, then A is “not harder than” B and B is “at least as hard as” A.
● Proof idea: For (1), show that applying the reduction from A to B and solving B solves A in polynomial time. For (2), show that applying the reduction from A to B lets us use a verifier for B to verify answers to A.
![Page 101: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/101.jpg)
Reducibility, Summarized
● A polynomial-time reduction is a way of transforming inputs to problem A into inputs to problem B that preserves the correct answer.
● If there is a polynomial-time reduction from A to B, we denote this by writing A ≤p B.
● Two major theorems:● Theorem: If B ∈ P and A ≤p B, then A ∈ P.
● Theorem: If B ∈ NP and A ≤p B, then A ∈ NP.
![Page 102: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/102.jpg)
NP-Hardness and NP-Completeness
![Page 103: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/103.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
If L1 ≤P L2 and L2 ∈ NP, then L1 ∈ NP.
P
![Page 104: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/104.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
If L1 ≤P L2 and L2 ∈ NP, then L1 ∈ NP.
P
![Page 105: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/105.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
If L1 ≤P L2 and L2 ∈ NP, then L1 ∈ NP.
P
![Page 106: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/106.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
● If A ≤P B and B ∈ NP, then A ∈ NP.
P
![Page 107: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/107.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
● If A ≤P B and B ∈ NP, then A ∈ NP.
NPP
![Page 108: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/108.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
● If A ≤P B and B ∈ NP, then A ∈ NP.
NPP
![Page 109: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/109.jpg)
Polynomial-Time Reductions
● If A ≤P B and B ∈ P, then A ∈ P.
● If A ≤P B and B ∈ NP, then A ∈ NP.
NPP
![Page 110: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/110.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
A language in L is called NP-complete iff L is NP-hard and L ∈ NP.
The class NPC is the set of NP-complete problems.
P
NP
![Page 111: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/111.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
A language in L is called NP-complete iff L is NP-hard and L ∈ NP.
The class NPC is the set of NP-complete problems.
P
NP NP-Hard
![Page 112: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/112.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
A language in L is called NP-complete iff L is NP-hard and L ∈ NP.
The class NPC is the set of NP-complete problems.
P
NP NP-Hard
![Page 113: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/113.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
A language in L is called NP-complete iff L is NP-hard and L ∈ NP.
The class NPC is the set of NP-complete problems.
P
NP NP-Hard
Intuitively: L has to be at least as hard as every problem in NP, since an algorithm for L can be used to
decide all problems in NP.
Intuitively: L has to be at least as hard as every problem in NP, since an algorithm for L can be used to
decide all problems in NP.
![Page 114: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/114.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
A language in L is called NP-complete iff L is NP-hard and L ∈ NP.
The class NPC is the set of NP-complete problems.
P
NP NP-Hard
![Page 115: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/115.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
A language in L is called NP-complete iff L is NP-hard and L ∈ NP.
The class NPC is the set of NP-complete problems.
P
NP NP-Hard
What's in here?What's in here?
![Page 116: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/116.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
● A language in L is called NP-complete if L is NP-hard and L ∈ NP.
● The class NPC is the set of NP-complete problems.
P
NP NP-Hard
![Page 117: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/117.jpg)
NP-Hardness
● A language L is called NP-hard if for every A ∈ NP, we have A ≤P L.
● A language in L is called NP-complete if L is NP-hard and L ∈ NP.
● The class NPC is the set of NP-complete problems.
P
NP NP-HardNPC
![Page 118: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/118.jpg)
The Tantalizing Truth
Theorem: If any NP-complete language is in P, then P = NP.
Proof: Suppose that L is NP-complete and L ∈ P. Now considerany arbitrary NP problem X. Since L is NP-complete, we knowthat X ≤p L. Since L ∈ P and X ≤p L, we see that X ∈ P. Sinceour choice of X was arbitrary, this means that NP ⊆ P, soP = NP. ■
![Page 119: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/119.jpg)
The Tantalizing Truth
NPP
NPCP
Theorem: If any NP-complete language is in P, then P = NP.
Proof: Suppose that L is NP-complete and L ∈ P. Now considerany arbitrary NP problem X. Since L is NP-complete, we knowthat X ≤p L. Since L ∈ P and X ≤p L, we see that X ∈ P. Sinceour choice of X was arbitrary, this means that NP ⊆ P, soP = NP. ■
![Page 120: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/120.jpg)
The Tantalizing Truth
NPP
NPC
Theorem: If any NP-complete language is in P, then P = NP.
Proof: Suppose that L is NP-complete and L ∈ P. Now considerany arbitrary NP problem X. Since L is NP-complete, we knowthat X ≤p L. Since L ∈ P and X ≤p L, we see that X ∈ P. Sinceour choice of X was arbitrary, this means that NP ⊆ P, soP = NP. ■
![Page 121: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/121.jpg)
The Tantalizing Truth
Theorem: If any NP-complete language is in P, then P = NP.
Proof: Suppose that L is NP-complete and L ∈ P. Now considerany arbitrary NP problem X. Since L is NP-complete, we knowthat X ≤p L. Since L ∈ P and X ≤p L, we see that X ∈ P. Sinceour choice of X was arbitrary, this means that NP ⊆ P, soP = NP. ■
NPP
NPC
![Page 122: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/122.jpg)
The Tantalizing Truth
P = NP
Theorem: If any NP-complete language is in P, then P = NP.
Proof: Suppose that L is NP-complete and L ∈ P. Now considerany arbitrary NP problem X. Since L is NP-complete, we knowthat X ≤p L. Since L ∈ P and X ≤p L, we see that X ∈ P. Sinceour choice of X was arbitrary, this means that NP ⊆ P, soP = NP. ■
![Page 123: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/123.jpg)
The Tantalizing Truth
P = NP
Theorem: If any NP-complete language is in P, then P = NP.
Proof: Suppose that L is NP-complete and L ∈ P. Now considerany arbitrary NP problem A. Since L is NP-complete, we knowthat A ≤p L. Since L ∈ P and A ≤p L, we see that A ∈ P. Sinceour choice of A was arbitrary, this means that NP ⊆ P, soP = NP. ■
![Page 124: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/124.jpg)
The Tantalizing Truth
NP
P NPC
Theorem: If any NP-complete language is not in P, then P ≠ NP.
Proof: Suppose that L is an NP-complete language not in P. SinceL is NP-complete, we know that L ∈ NP. Therefore, we knowthat L ∈ NP and L ∉ P, so P ≠ NP. ■
![Page 125: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/125.jpg)
A Feel for NP-Completeness
● If a problem is NP-complete, then under the assumption that P ≠ NP, there cannot be an efficient algorithm for it.
● In a sense, NP-complete problems are the hardest problems in NP.
● All known NP-complete problems are enormously hard to solve:● All known algorithms for NP-complete problems
run in worst-case exponential time.● Most algorithms for NP-complete problems are
infeasible for reasonably-sized inputs.
![Page 126: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/126.jpg)
How do we even know NP-completeproblems exist in the first place?
![Page 127: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/127.jpg)
Satisfiability
● A propositional logic formula φ is called satisfiable if there is some assignment to its variables that makes it evaluate to true.● p ∧ q is satisfiable.● p ∧ ¬p is unsatisfiable.● p → (q ∧ ¬q) is satisfiable.
● An assignment of true and false to the variables of φ that makes it evaluate to true is called a satisfying assignment.
![Page 128: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/128.jpg)
SAT
● The boolean satisfiability problem (SAT) is the following:
Given a propositional logicformula φ, is φ satisfiable?
● Formally:
SAT = { ⟨φ⟩ | φ is a satisfiable PL formula }
![Page 129: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/129.jpg)
Theorem (Cook-Levin): SAT is NP-complete.
Proof Idea: Given a polynomial-time verifier V for an NP language L, for any string w, you can write a gigantic formula φ(w) that says “there is a certificate c such that V accepts ⟨w, c⟩.” This formula is satisfiable iff there is a c where V accepts ⟨w, c⟩ iff w ∈ L. ■
Proof: Read Sipser or take CS154!
![Page 130: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/130.jpg)
Why All This Matters
● Resolving P ≟ NP is equivalent to just figuring out how hard SAT is.● If SAT ∈ P, then P = NP.● If SAT ∉ P, then P ≠ NP.
● We've turned a huge, abstract, theoretical problem about solving problems versus checking solutions into the concrete task of seeing how hard one problem is.
● You can get a sense for how little we know about algorithms and computation given that we can't yet answer this question!
![Page 131: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/131.jpg)
Finding Additional NP-Complete Problems
![Page 132: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/132.jpg)
NP-CompletenessTheorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let L₁ and L₂ be languages whereL₁ ∈ NPC and L₂ ∈ NP. If L₁ ≤P L₂, thenL₂ ∈ NPC.
![Page 133: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/133.jpg)
NP-Completeness
P
NP
NPC
Theorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let L₁ and L₂ be languages whereL₁ ∈ NPC and L₂ ∈ NP. If L₁ ≤P L₂, thenL₂ ∈ NPC.
![Page 134: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/134.jpg)
NP-Completeness
P
NP
NPC
Theorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let L₁ and L₂ be languages whereL₁ ∈ NPC and L₂ ∈ NP. If L₁ ≤P L₂, thenL₂ ∈ NPC.
![Page 135: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/135.jpg)
NP-Completeness
P
NP
NPC
Theorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let L₁ and L₂ be languages whereL₁ ∈ NPC and L₂ ∈ NP. If L₁ ≤P L₂, thenL₂ ∈ NPC.
![Page 136: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/136.jpg)
NP-Completeness
P
NP
NPC
Theorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let A and B be languages whereA ∈ NPC and B ∈ NP. If A ≤P B, thenB ∈ NPC.
![Page 137: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/137.jpg)
NP-Completeness
P
NP
NPC
Theorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let A and B be languages whereA ∈ NPC and B ∈ NP. If A ≤P B, thenB ∈ NPC.
![Page 138: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/138.jpg)
NP-Completeness
P
NP
NPC
Theorem: Let A and B be languages. IfA ≤P B and A is NP-hard, then B is NP-hard.
Theorem: Let A and B be languages whereA ∈ NPC and B ∈ NP. If A ≤P B, thenB ∈ NPC.
![Page 139: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/139.jpg)
Karp's 21 NP-Complete Problems
![Page 140: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/140.jpg)
Sample NP-Complete Problems
● Given a graph, is that graph 3-colorable?● Given a graph, does that graph contain a Hamiltonian
path?● Given a set of cities and a set of substation locations,
can you provide power to all the cities using at most k substations?
● Given a set of jobs and workers who can perform those tasks in parallel, can you complete all the jobs in at most T units of time?
● Given a set of numbers S, can you split S into two disjoint sets with the same sum?
● And many, many more!
![Page 141: NP-Completenessweb.stanford.edu/class/archive/cs/cs103/cs103.1164/... · 2016-03-08 · Why This Matters If P = NP: A huge number of seemingly difficult problems could be solved efficiently](https://reader033.vdocuments.us/reader033/viewer/2022042911/5f432d451887f90d526a3ebe/html5/thumbnails/141.jpg)
A Feel for NP-Completeness
● There are NP-complete problems in● formal logic (SAT),● graph theory (3-colorability),● operations research (job scheduling),● number theory (partition problem),● and basically everywhere.
● You will undoubtedly encounter NP-complete problems in the real world.