Tiny Experiments for Algorithms and Life

advertisement
Tiny Experiments for
Algorithms and Life
Jon Bentley
Avaya Labs Research
© 2006 Avaya Inc.
The Real Topic: Tiny MSE
Math, Science and Engineering (MSE)
Broad umbrella; “I know it when I see it”
Math: Symbolic reasoning, computation, statistics, …
Science: Experiments, physical models, …
Engineering: Applications, apparatus, calibration, …
Size
Ad hoc divisions from nano to jumbo
The small end of the scale
In one’s head – a fraction of a minute
On the back of an envelope – a few minutes
On a blank spreadsheet – fraction of an hour
….
Bentley – Tiny Experiments – p. 2
“Tiny”
The Thesis
Tiny MSE can be
Fun
Simple
Performed when and where it matters
Taught to college undergraduates
Useful
To algorithms researchers
To computer scientists
To real people making real-life decisions
To MSE teachers who want to motivate students
Ideally, in negative class time
Bentley – Tiny Experiments – p. 3
A Great Bug Report
We [Wilks and Becker] found that qsort is unbearably
slow on ``organ-pipe'' inputs like ``0123443210'':
main(int argc, char **argv)
{
int n=atoi(argv[1]), i, x[100000];
for (i = 0; i < n; i++)
x[i] = i;
for ( ; i < 2*n ; i++)
x[i] = 2*n-i-1;
qsort(x, 2*n, sizeof(int), intcmp);
}
(Continued …)
Bentley – Tiny Experiments – p. 4
Wilks and Becker, Cont.
Here are the timings on a Pentium:
$ time a.out 2000
real
5.85s
$ time a.out 4000
real
21.65s
$ time a.out 8000
real
85.11s
$
This is clearly quadratic behavior – each time we double
the input size, the run time goes up by a factor of four.
A simple experiment to reveal functional form: quadratic
when it should be (n log n)
Bentley – Tiny Experiments – p. 5
Tiny MSE Outdoors?
Dec 25, 2002
Bentley – Tiny Experiments – p. 6
How Much Snow?
Facts
The tent is a square, 2.7m on a side
The snow is 75cm high
Weight of snow
Light snow is about one-tenth as dense as water
A cc of water weighs 1g; a 10cm cube of water weighs 1kg
Calculation
A square meter of water 10cm deep weighs 100kg
A square meter of snow 75cm deep weighs about 75kg
The tent is about 7.2 square meters
The snow above me weighs about 540kg
Bentley – Tiny Experiments – p. 7
Mental Arithmetic
A hard problem
(2.7m)2  75kg/m2
Some easy problems
(3  0.9)2 = 32  0.92 = 9  .81 ~ 9  .8 = 7.2
7.2  75 = 720  ¾ = 3  (720 / 4) = 3  180 = 540
Principles
Re-express to convenient units
Re-order
Algebraic identities
Memorize tables of squares and powers of two
Rounding (slide rule arithmetic)
Tastefully choosing where to round
Bentley – Tiny Experiments – p. 8
Review of Experiments
Algorithmic
Qsort CPU times FF
Other
Snow on my tent
PE
Strings per second PE
Depth of a river PE
Frequency of names PE
Cost of memory PE
Qsort comparison counts HT Pressure in guns FF
K-d trees FF
CPU times of sorting
String reversal HR
FF
Shape of Pascal’s triangle
Typeface design HR
Functional Form
Parameter Estimation
Hypothesis Test
Horse Race
Bentley – Tiny Experiments – p. 9
FF
Sizes of Algorithmic Experiments
Minutes
A few CPU times
Quarter hour
A single graph, perhaps of operation counts
Hour
A directory and a few graphs
Day
A spreadsheet
Week
www.cs.amherst.edu/ccm/alglab/
Larger
…
Bentley – Tiny Experiments – p. 10
How I Live with Tiny MSE
Outdoors
To what temperature will my gear keep me alive? Comfy?
How far can I walk in a day? How much water do I need?
Checking: news, politics, …
Automobiles: debugging, mileage, …
Weather: thunderstorms, barometers, …
Cell phone: battery life, range,
Setting the temperature on my water heater
Shopping (beware opening price points)
Emergency medicine: linear fits, functional forms, …
Bentley – Tiny Experiments – p. 11
Outline
Two Pretty Examples
Qsort, Snow
Science
A zoo of experiments: Parameter estimation, Hypothesis
testing, Functional forms, Horse races
Math
Quick calculations, Rule of 72
Engineering
Eyeball Analyses, Heuristics, Cost Models
Teaching Tiny MSE
Bentley – Tiny Experiments – p. 12
Download