SUNY Geneseo, Department of Computer Science
CSci 141 , Fall 2003
Prof. Doug Baldwin
Due Wednesday, October 8
The Science of Computing presents an analysis of the following algorithm to move a robot forward a given distance (see Section 7.2.2, page 291):
public void takeJourney (int distance) {
if (distance > 0) {
move();
takeJourney (distance - 1);
}
}
By setting up a recurrence relation based on the recursion in the algorithm,
the book concludes that this algorithm uses n move
messages
to move the robot a distance of n tiles.
Your job in this lab is to carry out an experiment that tests the results of this analysis.
Design and conduct an experiment that tests a two-part hypothesis based on the analysis described in the "Background" section:
takeJourney
algorithm sends n move messages
in order to move a robot a distance of n tilestakeJourney
requires to move a robot n
tiles is proportional to n.Your experimental program will need a robot that can carry out the takeJourney
algorithm, while counting how many move
messages get sent. I will
talk in lab about a way to use subclasses and method "overriding"
to do this.
To test the second hypothesis, you will need to analyze the times you collect to see if they are proportional to n. Thinking about what "proportional" means may help you see a way to do this analysis. If not, ask and I will give you suggestions.
Most of the other things you need for this experiment are ones you already have experience with -- timing code, setting up reliable experiments and collecting data, etc. If you have questions, feel free to ask, or consult Chapter 4 of The Science of Computing.