
CS 302 Assignment 2:
Counting the Number of Comparisons of a Sorting Algorithm
Due date: Thursday, September 3, 2009, midnight.
All programming assignments must be
submitted electronically.
Submit them to the graduate assistant,
Abhinav Dasu, by email at
dasun"at"unlv"dot"nevada"dot"edu
on or before the due date.
Your email must come from your engineering college (or computer science
or computer engineering) account.
Write a program which
-
Reads real numbers from a file into an array of size no more than 1000,
and reports the size of that array.
-
Sorts the array using selection sort.
-
Sorts the array using bubblesort.
-
Counts the number of comparisons for each of the two sorting
algorithms, and reports that number.
Use the following four files to test your program:
a small file
a large file
a file that is "almost" sorted
Do you expect bubblesort to do better in this case?
another file that is almost sorted