© 2006 avaya inc. tiny experiments for algorithms and life jon bentley avaya labs research
TRANSCRIPT
Bentley – Tiny Experiments – p. 2
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
….
“Tiny”
Bentley – Tiny Experiments – p. 3
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 studentsIdeally, in negative class time
Bentley – Tiny Experiments – p. 4
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. 5
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. 7
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. 8
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. 9
Review of Experiments
Algorithmic
Qsort CPU times
Strings per second
Frequency of names
Qsort comparison counts
K-d trees
CPU times of sorting
String reversal
Other
Snow on my tent
Depth of a river
Cost of memory
Pressure in guns
Shape of Pascal’s triangle
Typeface design
FF PE
FF
FF
FF
HR
HR
PE
PE
PE
PE
HT
Functional Form
Parameter Estimation
Hypothesis Test
Horse Race
FF
Bentley – Tiny Experiments – p. 10
Sizes of Algorithmic ExperimentsMinutes
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. 11
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, …