![Page 1: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/1.jpg)
The CS 5 TimesPenguin Rescue!Dunedin, New Zealand (Penguin Press):
A daring mission has beenmounted to rescue two adorable penguinswho had been given up as lost after aspaceship crash. Risking her life with anuntested experimental jet pack, a brave Chemistry penguin mixed a witches’ brew of propellant, fueled the pack, and set off across the sky in search of her missing colleagues, who were running out of fish when last heard from.
“We are, like, so grateful for this, like, attempt, and, like, we, like, hope for her, like, success,” stated a jittery CS 5 student. “We like, love our, like, penguins and are, like, so helpless with our, like, homework assignments without, like, their, like, help.”
Further quotes were unavailable due to an unexpected attack from a WRIT 1 instructor.
![Page 2: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/2.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[
![Page 3: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/3.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,
✓
![Page 4: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/4.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2
✓ ✓
![Page 5: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/5.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2,3
✓ ✓✓
![Page 6: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/6.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2,3,5
✓ ✓✓ ✓
![Page 7: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/7.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2,3,5,7
✓ ✓✓ ✓ ✓
![Page 8: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/8.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2,3,5,7,8
✓ ✓✓ ✓ ✓ ✓
![Page 9: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/9.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2,3,5,7,8,27
✓ ✓✓ ✓ ✓ ✓ ✓
![Page 10: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/10.jpg)
Mergesort
msort([42, 3, 1, 5, 27, 8, 2, 7])
msort([42, 3, 1, 5]) msort([27, 8, 2, 7])
merge([1, 3, 5, 42], [2, 7, 8, 27])
[1,2,3,5,7,8,27,42]
✓ ✓✓ ✓ ✓ ✓ ✓✓
Done!
![Page 11: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/11.jpg)
Let’s try it out - and let’s not even make n a power of 2!
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
![Page 12: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/12.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
![Page 13: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/13.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
[42]
msort([3])msort([1])
![Page 14: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/14.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
[42]
msort([3])msort([1])
[3] [1]
![Page 15: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/15.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
[42]
msort([3])msort([1])
[3] [1]
[1,3]
![Page 16: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/16.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
[42]
msort([3])msort([1])
[3] [1]
[1,3]
[1,3,42]
![Page 17: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/17.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
[42]
msort([3])msort([1])
[3] [1]
[1,3]
[1,3,42] [2, 5, 6, 7]
![Page 18: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/18.jpg)
msort([42, 3, 1, 6, 5, 2, 7])
msort([42, 3, 1]) msort([6, 5, 2, 7])
msort([42]) msort([3, 1]) msort([6, 5]) msort([2, 7])
[42]
msort([3])msort([1])
[3] [1]
[1,3]
[1,3,42] [2, 5, 6, 7]
[1, 2, 3, 5, 6, 7, 42]
![Page 19: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/19.jpg)
How “Efficient” Is Mergesort?
![Page 20: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/20.jpg)
How big a deal is this?
The Meder-O-Matic Supercomputer: 100 billion steps/second
n2 algorithm n log2 n algorithm
n = 108 11.5+ days
![Page 21: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/21.jpg)
How big a deal is this?
The Meder-O-Matic Supercomputer: 100 billion steps/second
n2 algorithm n log2 n algorithm
n = 108 11.5+ days 0.27 seconds
![Page 22: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/22.jpg)
“Easy” Problems
Sorting a list of n numbers: [42, 3, 17, 26, … , 100]
Multiplying two n x n matrices:
3 5 2 7 1 6 8 9 2 4 6 10 9 3 2 12
( ) 1 5 5 4 5 12 8 6 7 6 1 5 9 23 5 8
( ) = ( )n
n
n n
n
n log2 n
![Page 23: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/23.jpg)
“Easy” Problems
The Shortest Path Problem (i.e. “Google Maps”)
Edsgar Dijkstra
![Page 24: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/24.jpg)
“Easy” Problems
“Polynomial Time” = “Efficient”
n, n2, n3, n4, n5,…
How about something like n log2 n ?
The “class” P
sorting
matrix multiplication shortest paths
![Page 25: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/25.jpg)
“Hard” Problems
Snowplows of Northern Minnesota
Burrsburg
Frostbite City
Shiversville
Tundratown
FreezeapolisBrute-force? Greed?
![Page 26: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/26.jpg)
“Hard” Problems
The Traveling Salesperson Problem
New York
Moscow
Paris
San Francisco
Claremont
366
5625
1545
4664
5868
Brute Force? Greed?
2417
6060
2566
36275563
![Page 27: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/27.jpg)
The Hamiltonian Path Problem
Rome, GA
Athens, GA
Homer, GA
Damascus, GA
Bethlehem, GAThose are some peachy names!
William Rowan Hamilton
![Page 28: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/28.jpg)
n2 Versus 2n
The Meder-O-Matic performs 109 operations/sec
Meder-O-Matic
n2
2n
n!
n = 10 n = 30 n = 50 n = 70
100 < 1 sec
900 < 1 sec
2500 < 1 sec
1024 < 1 sec
109 1 sec
1015 11.6 days
4900 < 1 sec
1021 31,688 years
< 1 sec 1016 years 1057 years 1093 years
![Page 29: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/29.jpg)
Here’s an Idea!
n n2 n3 n5 2n n!
Size of largest problem solvable with “old” computer in one hour = S
Size of largest problem solvable with “new” twice-as-fast computer in one hour
2S 1.41S 1.26S 1.15S S+1 S
Let’s just buy a computer that’s twice as fast!
![Page 30: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/30.jpg)
Snowplows and Traveling Salesperson Revisited!
So are there polynomial time algorithms for the Snowplow and Travelling Salesperson, and Hamiltonian Path Problems?!
Travelling Salesperson Problem
Snowplow Problem
…
Hamiltonian Path Problem
NP-complete problems
Tens of thousands of other known problems go in this cloud!!
![Page 31: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/31.jpg)
Snowplows and Travelling Salesperson Revisited!
Travelling Salesperson Problem
Snowplow Problem
…
Hamiltonian Path Problem
NP-complete problems
Tens of thousands of other known problems go in this cloud!!
If a problem is NP-complete, it doesn’t necessarily mean that it can’t be solved in polynomial time. It does mean…
![Page 32: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/32.jpg)
“I can’t find an efficient algorithm. I guess I’m too dumb.”
Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson
![Page 33: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/33.jpg)
Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson
“I can’t find an efficient algorithm because no such algorithm is possible!”
![Page 34: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/34.jpg)
Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson
“I can’t find an efficient algorithm, but neither can all these famous people.”
![Page 35: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/35.jpg)
$1 million
Vinay Deolalikar
![Page 36: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/36.jpg)
What Is This?!
![Page 37: The CS 5 Timesjulie/cs5/f18/Lecture07Black.pdf · Cartoon courtesy of “Computers and Intractability: A Guide to the Theory of NP-Completeness” by M. Garey and D. Johnson “I](https://reader033.vdocuments.net/reader033/viewer/2022052011/6026c8c71123017a33569b8d/html5/thumbnails/37.jpg)
Are There Problems That Are Even Harder Than NP-Complete?
Kryptonite problems?