monkeysort keith gallagher university of durham loyola college in maryland presented by lewis berman
TRANSCRIPT
![Page 1: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/1.jpg)
MonkeySort
Keith GallagherUniversity of Durham
Loyola College in Maryland
presented by
Lewis Berman
![Page 2: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/2.jpg)
What Do Computer Scientists Do All Day?
• Write Code?
• Think about confusing things?
• Fill out spreadsheets?
• Play video games?
• ?
![Page 3: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/3.jpg)
Some of Our Big Ideas
• NP Hard – the ones with best known solutions equivalent
to “Guess and Test”
• Partial Correctness– the program is correct if it stops!
• Algorithmic and Empirical Analysis
![Page 4: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/4.jpg)
MonkeySort
• Simple
• Easy (for non-programmers)
to understand
• NP
• Partially correct
• Fun!
![Page 5: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/5.jpg)
MonkeySort
What doesComputer Scientist
Do?
EmpiricalAnalysis
Reasoningabout
Programs
AlgorithmAnalysis
CodeReading
Unix Top Utility
Processor vs.Run Time
Integer Overflow
Permutations asProduct of
Transpositions
Code CoverageTools
Fun!
Stirling’sApproximation
P vs. NP
Assertions
Guess andTest
![Page 6: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/6.jpg)
the Details• Early MonkeySort
– throw cards in tub– stir– pick up cards– until sorted– this may take a while...
Bathtub of the USS Maine (raised 1911, Havana Harbor)Source: http://www.roadsideamerica.com/attract/OHFINbathtub.html
![Page 7: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/7.jpg)
Evolved MonkeySort
• Guessing two array elements to swap– could be the same one
• Do Not Compare, just exchange– equivalent to “throw/stir/pick-up”
• Will it ever stop?– it hasn’t not stopped yet
(for < 14 values)…
![Page 8: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/8.jpg)
Sort Examples
82617354
87612354
62345178
12345678
QED! Not so QED…
87412356
87612354
![Page 9: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/9.jpg)
The Program Itself
• Uses system time and command line arguments
• C++ vector class
• Is Partially Correct– discuss reasoning about programs
• NP, as solution is “guess and test”
![Page 10: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/10.jpg)
Results and Observations:Things to Talk About
• It does halt
• Can you guess beforehand about how guesses it will take?
• Time to halt varies– larger sets may sort faster than smaller
• Best-known technique to solve the “garbage truck problem” ie. shortest Hamiltonian circuit.
![Page 11: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/11.jpg)
Screen Shot of “top” Utility
![Page 12: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/12.jpg)
Some Bigger Ideas
• Stirling’s approximation
• Code coverage tools
• Integer overflow
• Permutations as products of transpositions
• Is P == NP?
• Comparison of analytical results with empirical results
![Page 13: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/13.jpg)
What Do Computer Scientists Do All Day?
• Look for “better” solutions– build
• Experimentally determine program properties
• Must carefully consider all solution properties (overflow, timing, etc)
• CPU cycles are cheap; people are expensive: “work smart, not hard”
![Page 14: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman](https://reader035.vdocument.in/reader035/viewer/2022080917/56649edc5503460f94bec7ef/html5/thumbnails/14.jpg)
thanks for listening!