next up previous
Up: APS105S Home

APS 105S - Computer Fundamentals

Assignment #8:  Sorting

Winter 1999

To be completed for your lab period March 8-9, but you can get it marked any time before the project is marked. Please note that you must know this material for the quiz on March 12, and for the lab exam on March 15/16. This lab is very difficult.

 

Objective:   To experiment with several sorting algorithms and measure their running time on different data set sizes. To learn one method for sorting linked lists.

1. Sorting Arrays

For this part of the assignment you will be running two different sorting algorithms on the same sets of data and measuring how much work each algorithm does. To measure the amount of work each algorithm does, you should ``instrument'' the code so that it counts the number of times it makes a comparison between two numbers in the data set (i.e., how many times the 'if(...)' statement is executed).

This count of comparisons will be our measure of ``work''. Your program should do the following for arrays of various sizes:

1.
Generate an array of random numbers (double values in the range [0,1); use the function Math.random() to give you a random number).
2.
Make a copy of the array and sort it using the bubble sort algorithm 1.
3.
Make a copy of the array and sort it using the bubble sort algorithm 2.
4.
Make a copy of the array and sort it using the quicksort algorithm.
5.
Output the size of the array and the amount of work each algorithm did.
Do this for arrays of size 1000, 2000, ..., 10,000 (i.e. all multiples of 1000 between 1000 and 10,000). If you wish, you may try other array sizes.

Plot the results of your experiment. You may plot your results by hand on a piece of paper, or you may use a plotting package, such as xgraph. To learn how to use xgraph, type ``man xgraph'' in a Unix window. If you wish, you may write an applet to plot your results.

2. Sorting Linked Lists

Write a version of the quicksort algorithm that sorts a linked list of integers. Do not copy the list into an array and then sort the array. You must write a version of quicksort that directly sorts the list.

Write a program to test your implementation (and to demonstrate it for marking).


next up previous
Up: APS105S Home
Guy G. Lemieux
1999-03-19