CS107 - Lab 4

Due Wednesday 10/1 at the beginning of class.


Some of the most important algorithms used in computing are in the category "search and sort." These are useful in a variety of settings, such as web search, alphabetic sorting of a list of names, etc. They are also related, since the most efficient search algorithms occur on lists that are sorted. This lab provides an opportunity to explore the functioning of search and sort algorithms, as well as their efficiency. The readings and problems for this assignment are in Chapter 3 of your text.

Course software

Following the same steps that you used for Assignment 2, double-click the icon csci107 - Invitation (OSX) that you copied to the desktop. The following menu should appear:

The buttons Search Animator, Sort Animator and Sort Timer will be useful for this assignment. When you select either of these, you will be able to animate the behavior of several different algorithms in Chapter 3, as well as empirically measure the efficiency of different sorting algorithms on different amounts of data.

For example, select Algorithm -> Selection Sort in the Sort Animator and then select the Run button. You may Reset and Rerun this exercise several times to get a feeling for how the algorithm works. To count the number of exchanges and comparisons in a particular selection sort, you can repeatedly click the Step button and keep track of the number of times steps 9 and 6 are repeated, respectively.

Now opn the Sort Timer and select Algorithm -> Selection Sort and Points -> 128, and then select Run. Note that this gives the running time for selection-sorting 128 data points, and it graphically displays the behavior of the data being rearranged as the algorithm proceeds.

These animators will be useful for answering some of the questions below.

Algorithmic Problem Solving

Complete exercises 12, 17, 18, 19, 20, 22, 26, and 28 on pages 110-112 of your textbook.

Be sure to justify your answers! You may do this work either by hand or with a word processor (e.g. MS Word). Also, you may choose to do this assignment either by yourself or in a group. However, solutions should be written up individually and handed in on Monday, at the beginning of class.

To submit a file electronically, you should first rename it so that you are identified as the author (e.g., give it a name like lab-x-ltoma). Then drag the file to the csci107 -> Drop Box folder. Be careful not to drag an entire folder into the Drop Box; only a single file at a time can be submitted.