Instructor Notes

Chapter 4 — Experimentation: An Introduction to the Scientific Method

Supplemental Material for Baldwin and Scragg, Algorithms and Data Structures: The Science of Computing; Charles River Media, 2004 (Now published by Cengage Learning)

Site Index


Each of chapters 2, 3, and 4 of Algorithms and Data Structures: The Science of Computing delves into one of computer science’s methods of inquiry by exploring some element of that method in detail. In chapter 4, the general method is empirical analysis, and the specific element is experimentation. Many students assume that “experiment” in computer science simply means casually running a program and seeing what happens. One of the most important lessons of this chapter is that in fact experiments are not trivial activities, that a convincing experiment actually requires careful design of experimental procedures and mathematical analysis of data.

Interacting Methods of Inquiry

While chapters 2, 3, and 4 nominally place each method of inquiry into its own chapter, they also illustrate that the methods are not really as easily separable as this organization suggests. Chapter 4 starts by wondering whether chapter 3’s theoretical analyses of algorithms’ performance are too abstract to capture real-world behavior, thereby motivating the need to test theoretical models empirically. Just as chapter 2 discussed algorithms as things that can be designed, and chapter 3 introduced mathematical tools for reasoning about algorithms, chapter 4 discusses the design of experiments, and introduces some simple mathematics for data analysis.

The inseparability of computer science’s methods of inquiry is a theme that should pervade courses based on Algorithms and Data Structures: The Science of Computing. Students should finish such courses (and readers should finish the book) appreciating that even if they most enjoy one method (e.g., some enjoy crafting programs, others enjoy proving theorems), they will be more successful in that method if they can also understand and use the others.

Classroom Activities

Demonstrating, or, even better, collectively designing and carrying out, an experiment is an ideal classroom activity to accompany this chapter. The goals of such an activity are to give students a concrete sense for what a good experiment is, to make sure they understand what the steps of an experiment and related terminology are (e.g., variables, experimental procedure, error sources, data, data analysis, etc.), and to bring out any questions or misconceptions students have about the chapter. Students should therefore be deeply involved in designing and conducting the experiment. Expect the activity to involve a lot of discussion between instructor and students, and to take a substantial amount of time (I like to use an hour to an hour and a half for it).

Experiments that I have used for this purpose include

Other Teaching Tips

Laboratory exercises in which students do experiments are particularly important ingredients in learning experimentation. Such exercises teach specific experimental techniques, data analyses, etc. This chapter is an excellent place for students to do their first formal computer science experiment, if they haven’t done one earlier. Of the laboratory exercises that accompany Algorithms and Data Structures: The Science of Computing, either the one entitled Introduction to Experimentation, or the one entitled Computer Science’s Methods of Inquiry, provide good first experiments.

This book makes a distinction between an experiment’s hypothesis and its prediction. A hypothesis is a general belief that an experiment tests (for example, “Insertion Sort runs in Θ(n2) time”), while a prediction is a specific expectation about the results of data analysis (for example, “dividing the running time of Insertion Sort by the square of the array size will yield a constant, even as array size varies”). This is, however, a subtle distinction, and many students have trouble understanding it. Instructors should be prepared to work with students to clarify it. Alternatively, concentrating on hypotheses when discussing experiments, and treating predictions as just the results one should see from data analysis if the data support the hypothesis, does little harm. For instance, the previous examples of a hypothesis and prediction about Insertion Sort could be presented as a formal hypothesis that Insertion Sort’s execution time is Θ(n2), followed by observing that hypotheses about execution time being Θ( f(n) ) can always be tested by dividing measured times by f(n) and looking for a constant, and that this rule can be applied to this hypothesis.

Further Reading

An illuminating explanation of pitfalls in timing Java programs appears in

S. Hansen, “Interpreting Java Program Runtimes,” Proceedings of the Thirty-Sixth SIGCSE Technical Symposium on Computer Science Education, Feb. 23 – 27, 2005 (SIGCSE Bulletin 37:1, Mar. 2005), pp. 36 – 40.


Copyright © 2005 Charles River Media. All rights reserved.

Revised Aug. 9, 2005 by Doug Baldwin

Site Index