fea-mcgeoch.qxp 2/2/01 11:58 AM Page 304
Experimental Analysis of Algorithms Catherine C. McGeoch
As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality. —Albert Einstein
In theory there is no difference between theory and practice. In practice there is. —Yogi Berra
he algorithm and the program. The given applications. Another effort focuses on using abstract and the physical. If you want to experiments to extend and improve the kinds of understand the fundamental and uni- results obtained in traditional algorithm analysis. versal properties of a computational That is, rather than having a goal of measuring pro- process, study the abstract algorithm grams, we develop experiments in order to better Tand prove a theorem about it. If you want to know understand algorithms, which are abstract math- how the process really works, implement the ematical objects. In this article we concentrate on algorithm as a program and measure the running examples from this latter type of research in ex- time (or another quantity of interest). perimental algorithmics. This distinction between the abstract model It is natural to wonder whether such an effort and the physical artifact exists in the study of is likely to bear fruit. If the ultimate goal of algo- computational processes just as in every other rithm analysis is to produce better programs, area of mathematical modeling. But algorithmic wouldn’t we be better off studying programs in problems have some unusual features. For exam- their natural habitats (computers) rather than per- ple, we usually build models to serve as handy rep- forming experiments on their abstractions? Con- resentations of natural phenomena that cannot versely, if the goal is to advance knowledge in an be observed or manipulated directly. But programs area of mathematical research (algorithm analysis), and computers are completely accessible to the re- are we wise to study abstract objects using im- searcher and are far more manipulable than, say, perfect, finite, and ever-changing measurement weather patterns. They are also much easier to tools? understand: hypothetically, one could obtain com- One answer to the first question is that reliable plete information about the behavior of a program program measurement is not as easy as it sounds. by consulting technical documents and code. And Running times, for example, depend on complex finally, algorithms are usually invented before pro- interactions between a variety of products that grams are implemented, not the other way around. comprise the programming environment, includ- This article surveys problems and opportunities ing the computer chip (perhaps Intel Inside), mem- that lie in the interface between theory and prac- ory sizes and configurations, the operating system tice in a relatively new research area that has been (such as Windows 98 or Unix), the programming called experimental algorithmics, experimental language (maybe Java or C), and the brand of com- analysis of algorithms, or algorithm engineering. piler (like CodeWarrior).1 These products are so- Much work in this field is directed at finding and phisticated, varied in design, and, especially when evaluating state-of-the-art implementations for 1Intel InsideTM is a registered trademark of the Intel Catherine C. McGeoch is an associate professor of Corporation. WindowsTM 98 is a registered trademark of computer science at Amherst College. She has been Microsoft Corporation. UnixTM is a registered trademark active in the development of an experimental of The Open Group. JavaTM is a registered trademark of tradition in algorithmic studies. Her e-mail address is Sun Microsystems, Inc. C is not a trademark. CodeWar- [email protected]. riorTM is a trademark of Metrowerks, Inc.
304 NOTICES OF THE AMS VOLUME 48, NUMBER 3 fea-mcgeoch.qxp 2/2/01 11:58 AM Page 305
1. Array A[1 ...n] contains n distinct numbers. We want the r th smallest. Set lo 1 and hi n. 2. Partition. Set x A[lo]. Rearrange the numbers in A[lo...hi] into three groups around some index p such that: a. For lo i