Sorting Algorithm Performance Analysis Assignment, Assignments of Computer Science

An assignment for a university course on programming, focusing on analyzing the performance of three sorting algorithms: insertion sort, selection sort, and shell sort. Students are required to generate random permutations and fixed sequences of different sizes, use each sequence as input for the respective sorting algorithms, determine their execution times, and analyze the big-oh run-time and performance based on data order. Additionally, students are asked to experiment with different shell sort parameters.

Typology: Assignments

Pre 2010

Uploaded on 11/08/2009

koofers-user-nil
koofers-user-nil 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Title: “Program Assignment 2: Analyzing Sorting Algorithm Performance”
Points: 100 points – 60pts for coded portion, 40 points for written analysis
Due Date: Wednesday October 23, 2002
Objectives: (1) To reinforce the concepts underlying the asymptotic behavior of several sorting
algorithms. (2) Further develop Java programming skills.
Description: Create a Java program that produces the necessary data to analyze the asymptotic
behavior of three sorting algorithms. Do this according to the steps shown below:
1. You will need to generate 3 random permutations of the first N integers for values of N
equal to 100, 500, 1000, 5000, and 10,000 (you may need to adjust the sizes of N) as well as
fixed permutations 1..N and N..1 when N = 500. Thus for each value of N you will have
five arrays: 3 permuted and 2 fixed sequences.
2. Once the arrays are generated use a copy of each of them as input to the following sorting
algorithms: (a) insertion sort, (b) selection sort, and (c) Shell sort with the initial gap and a
decrement of N/2.
3. Determine the execution time required by each of the sorting algorithms on all five of the
arrays (for each size of N) (be sure to get non-zero times).
4. Analyze the data for each of the sorts on the five different array sizes to determine the
following:
a. Using the T(N)/F(N) technique determine the Big-Oh run-time for each of the three
sorting algorithms. For insertion and selection sorts produce T(N)/F(N) tables for
F(N) = N, N2, and N3. For Shell sort produce T(N)/F(N) tables for F(N) = N, N1.5,
and N2..
b. Separate the data to determine if the sorting algorithm performance is affected by the
order of the data. In other words, can you tell a difference in the running time of the
sort if the data is already sorted (1..N fixed permutation) or is reverse sorted (N..1
fixed permutation).
5. Additional analysis for Shell sort. As we indicated in class; the Shell sort is a “tunable” sort
since the initial gap and decrement parameters can be altered to produce changes in the
performance of the algorithm. In this part of the project you will alter these parameters to
determine their effect on the sort. Use just two different sized arrays, say 1000 and 10,000
for this part of the project. Run several different experiments to obtain data for analysis of
this sorting algorithm. Try initial gap sizes of 1.8, 2.0, 2.2, and 2.4. Try decrements of
straight division by 2, straight division by 2.2 (using floor function), and only odd gaps.
Also test for random permutations as well as the fixed permutations.
6. 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 necessary to print the sorted output arrays only
Page 1
COP 3503H – Programming Assignment #2 – Fall 2002
pf2

Partial preview of the text

Download Sorting Algorithm Performance Analysis Assignment and more Assignments Computer Science in PDF only on Docsity!

Title: “Program Assignment 2: Analyzing Sorting Algorithm Performance” Points: 100 points – 60pts for coded portion, 40 points for written analysis Due Date: Wednesday October 23, 2002 Objectives: (1) To reinforce the concepts underlying the asymptotic behavior of several sorting algorithms. (2) Further develop Java programming skills. Description: Create a Java program that produces the necessary data to analyze the asymptotic behavior of three sorting algorithms. Do this according to the steps shown below:

  1. You will need to generate 3 random permutations of the first N integers for values of N equal to 100, 500, 1000, 5000, and 10,000 (you may need to adjust the sizes of N) as well as fixed permutations 1..N and N..1 when N = 500. Thus for each value of N you will have five arrays: 3 permuted and 2 fixed sequences.
  2. Once the arrays are generated use a copy of each of them as input to the following sorting algorithms: (a) insertion sort, (b) selection sort, and (c) Shell sort with the initial gap and a decrement of N/2.
  3. Determine the execution time required by each of the sorting algorithms on all five of the arrays (for each size of N) (be sure to get non-zero times).
  4. Analyze the data for each of the sorts on the five different array sizes to determine the following: a. Using the T(N)/F(N) technique determine the Big-Oh run-time for each of the three sorting algorithms. For insertion and selection sorts produce T(N)/F(N) tables for F(N) = N, N^2 , and N^3. For Shell sort produce T(N)/F(N) tables for F(N) = N, N1.5, and N2.. b. Separate the data to determine if the sorting algorithm performance is affected by the order of the data. In other words, can you tell a difference in the running time of the sort if the data is already sorted (1..N fixed permutation) or is reverse sorted (N.. fixed permutation).
  5. Additional analysis for Shell sort. As we indicated in class; the Shell sort is a “tunable” sort since the initial gap and decrement parameters can be altered to produce changes in the performance of the algorithm. In this part of the project you will alter these parameters to determine their effect on the sort. Use just two different sized arrays, say 1000 and 10, for this part of the project. Run several different experiments to obtain data for analysis of this sorting algorithm. Try initial gap sizes of 1.8, 2.0, 2.2, and 2.4. Try decrements of straight division by 2, straight division by 2.2 (using floor function), and only odd gaps. Also test for random permutations as well as the fixed permutations.
  6. 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 necessary to print the sorted output arrays only Page 1

COP 3503H – Programming Assignment #2 – Fall 2002

once for each sort (to prove the sort works properly) – if your sorts work properly all of the output should look identical so you don’t need to repeat it.

References: Notes: Lecture Notes for Days 10 & 11 (Sorting) Restrictions: Your source file shall begin with comments containing the following information: / Name: COP 3503H Assignment title: Date: / Input Specification: Internal to the source code. Output Specification: Timing information and any other output produced by your program can be written to the screen for this program. All other information should be included in your write-up. Deliverables: (1) Source code file on a floppy disk with the following information: Your name, COP 3503H, Assignment title, and Date. (2) The write-up for this assignment described in other parts of this document. (3) Place hard copies of (1) and (2) along with your disk in a large envelope, so that you do not need to fold the printouts or your report. CLEARLY, label the envelope with the following information: your name, COP 3503H, Assignment title, and the date. Write-up: A complete write-up is one of the deliverables for this assignment. A separate document (see the course web-site) describes the make-up of this write-up. Along with the items described in that separate document you will need to include the analysis described above in your report. Additional Information: Shown below is a segment of code that will be helpful in constructing random permutations. Random permutation public static final void permute( Object [ ] myarray ) { Random r = new Random( ); for (int i = 1; i < myarray.length; i++) swapElements (myarray, i, r.nextInt(0, i)); } Timing Just as in Program # Page 2