monkeysort keith gallagher university of durham loyola college in maryland presented by lewis berman

14
MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman

Upload: avis-peters

Post on 02-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman

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

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

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

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

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

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

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

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

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

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

Screen Shot of “top” Utility

Page 12: MonkeySort Keith Gallagher University of Durham Loyola College in Maryland presented by Lewis Berman

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

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

thanks for listening!