
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Due Date: March 27, 2001 at class time. Points: 100 total – program 60 points, write-up 40 points Objective: You will implement the Insertion sort, the Shell sort, and the Quick sort algorithms (all of which appear in the class notes) and produce a timing analysis for all three algorithms using input arrays of various size N which will be produced both as random permutations of the first N integer numbers as well as fixed permutations. This programming assignment will reinforce various techniques discussed thus far in class involving algorithm analysis, sorting techniques, and randomization. Technique: You will need to generate 3 random permutations of the first N integers for values of N equal to 100, 500, and 1000 (an algorithm to do this appears on page 268 in your textbook) as well as fixed permutations 1..N and N..1 when N = 500. Thus your five arrays are: Array 1: random permutation of first 100 integers. Array 2: random permutation of first 500 integers. Array 3: random permutation of first 1000 integers. Array 4: fixed permutation 1..500. Array 5: fixed permutation 500..1. Once your arrays are generated use copies of each of these arrays as the input to each of the three sorting algorithms. Time each of the sorting algorithms on each set of input data. You will generate T(100), T(1000), and three T(500) values for each of the three algorithms. Verify that the average running time for each of the three sorts matches the expected value with respect to Big-Oh analysis. In addition to the timing, insert counters into each algorithm which will count the total number of comparisons that occur during the course of a sort. For the Shell sort algorithm, set the initial increment as N/2 and halve it at each step (use a floor function) until the final increment is 1. For the Quick sort use the median of three technique for determining the value of the pivot element. For all the sorts in this program, assume that we want to sort in ascending order. Although you may want to actually print out the sorted arrays while you are working on your program, to make sure it works – it will be necessary to print the output arrays in your final version only once from each algorithm (do the array of size 100) – if your program works properly all of the output should look identical so you don’t need to repeat them. Write-Up: The write-up of this programming assignment is to follow the general guidelines of the write-up for program #1 (these are posted on the web site). For this program you will need to specifically include the following: (1) Describe the technique that you used to produce the data sets for the different runs made by the sort algorithms. (2) An analysis of the timing verification of all three sorting algorithms produced by the various runs defined above. (3) For the three different arrays of size 500, analyze each sort independently to determine how the input array affected the running time of the sort? What affect did it have? Which input data produced the fastest run? Why? Again, like in program #1, if your numbers do not verify the analysis, give justification for the disagreement. (4) How did the number of comparisons performed by each of the sorting algorithms compare? Were the numbers what you expected? Why or why not? Submission of the Assignment : Turn in a hard copy of your source code, any output produced by your program and the write-up detailing your program and the results you have produced.