the cs 5 timesjulie/cs5/f18/lecture07black.pdf · cartoon courtesy of “computers and...
TRANSCRIPT
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.
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])
[
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,
✓
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
✓ ✓
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
✓ ✓✓
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
✓ ✓✓ ✓
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
✓ ✓✓ ✓ ✓
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
✓ ✓✓ ✓ ✓ ✓
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
✓ ✓✓ ✓ ✓ ✓ ✓
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!
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])
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])
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])
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]
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]
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]
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]
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]
How “Efficient” Is Mergesort?
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
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
“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
“Easy” Problems
The Shortest Path Problem (i.e. “Google Maps”)
Edsgar Dijkstra
“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
“Hard” Problems
Snowplows of Northern Minnesota
Burrsburg
Frostbite City
Shiversville
Tundratown
FreezeapolisBrute-force? Greed?
“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
The Hamiltonian Path Problem
Rome, GA
Athens, GA
Homer, GA
Damascus, GA
Bethlehem, GAThose are some peachy names!
William Rowan Hamilton
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
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!
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!!
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…
“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
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!”
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.”
$1 million
Vinay Deolalikar
What Is This?!
Are There Problems That Are Even Harder Than NP-Complete?
Kryptonite problems?