Objectives and Overview: This lab provides a chance to become familiar with basic ideas of "computational complexity," which is a way of measuring the efficiency of programs. What makes a particular program the most efficient solution to a given problem, and how do we know how efficient it is? The sorting problem provides a good vehicle for exploring the complexity of alternative solutions. That is, find a program for rearranging the numbers in a list into ascending order, and then measure (estimate) the running time for your program. Is there a faster program, using a different approach to sorting? Chapter 4 in your text introduces tools for measuring the complexity of programs, while Chapter 5 presents several different sorting programs and discusses their complexity.
To be sure that you understand the basic ideas of computational complexity and recursion, answer the following questions in Chapter 4 of your text.
Now start CodeWarrior and create a new project called Lab3.µ on the desktop. Add the sortDriver.java program file to your project, along with the two additional files shown below. These files can be found in the Courses -> CS210 (Tucker) -> examples folder; copies of all these files should be dragged to the desktop before adding them to your project.
The sortDriver program is a utility program to exercise any of the sorting algorithms that are presented in Chapter 5 of your text. As it stands, it is set up to exercise the bubbleSort method (see p 68 of your text). The program calls for an integer n and then generates n random integers in the range 0-999. After calling bubbleSort, the program displays the sorted list and the elapsed time in milliseconds to accomplish this sort.
A sample of the output for this program is shown below:
To run this program, recall that the following actions need to be taken with your project Lab3.µ. Select TrivialApplication Settings under the Edit menu, and a settings window will appear. Now make three changes in this window:
Now close this window and Make and Run your project. The output should appear in the Java Output window after you type a number in the System.in window. For example, if you type the input
10
the program will give output similar to that shown above (the millisecond timing number may be different). Now run this program and check that it is working properly.
Now run this program several (12) times, recording the elapsed time in milliseconds for each run.
This exercise provides a way to empirically measure the complexity of different sorting algorithms.
Hand in your answers to the questions in Parts 1 and 3 of this lab. Also, hand in a hard copy of the output from a single run of the sortDriver program, for input size n = 100.