Espresso: A Concentrated Introduction to Java
Summary: In this laboratory, you will have an opportunity to analyze some standard algorithms theoretically and experimentally.
Contents:
exptFor
exptWhile
sequentialSearch
binarySearch
Required Code Files:
a. Create a package named
username.analysis.
b. Make a copy of
Computer.java.
c. Update that file to use your package name.
Make sure to do this exercise with at least one colleague!
If you look at
Computer.java, you will see that it contains four central methods:
exptFor
exptWhile
sequentialSearch
binarySearch
Look at the methods, and, for each, which function best models the running time of that function. It is likely that you will find that some are O(log2n), some are O(n), some are O(n2), and perhaps that some are best modeled by some other function.
If you look again at
Computer.java, you will see that it also contains a few bookkeeping methods,
particularly reset, step, and steps.
Explain the purpose of those methods. You may also want to look at
the main method to see how they are used.
If you look at the main method, you'll see the lines
alpha = System.currentTimeMillis(); ... omega = System.currentTimeMillis();
Explain the purpose of those lines.
exptFor
a. Compile and run Computer.
b. Graph the results. (You should have two graphs, one for steps and one for time.)
c. Determine whether exptFor behaves as you expected.
exptWhile
a. Modify the main method of Computer so that it
tests exptWhile rather than exptFor.
b. Compile and run Computer.
c. Graph the results. (You should have two graphs, one for steps and one for time.)
d. Determine whether exptFor behaves as you expected.
sequentialSearch
a. Modify the main method of Computer so that it
tests sequentialSearch. Note that you'll need to create an array
in which to search and to search for a variety of values. I'd recommend that
you also try a variety of array sizes. You may find the randomArray method useful.
b. Compile and run Computer.
c. Graph the results. (You should have two graphs, one for steps and one for time.)
d. Determine whether exptFor behaves as you expected.
binarySearch
a. Modify the main method of Computer so that it
tests binarySearch. Note that the arrays you create must be
sorted in increasing order. You may find it useful to build a variant of
randomArray for this purpose.
b. Compile and run Computer.
c. Graph the results. (You should have two graphs, one for steps and one for time.)
d. Determine whether exptFor behaves as you expected.
Wednesday, 16 March 2005 [Samuel A. Rebelsky]
Monday, 31 October 2005 [Samuel A. Rebelsky]
This page was generated by
Siteweaver on Thu Mar 30 15:24:33 2006.
The source to the page was last modified on Mon Oct 31 09:53:38 2005.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Espresso/Labs/analysis.html.
You may wish to
validate this page's HTML
;
;
Check with Bobby