CIS 068 / 2: Lab-Assignment #8: Comparison of Selection and Bubble Sort
Write a program that will help you compare the two sorting algorithms selection and bubble sort with regard
to the number of compares and number of record moves.
Please implement Bubble Sort and Selection Sort as separate classes. You may use the sources given in the textbook
or any source you find in the web. In order to compare the algorithms, your classes must provide a variable to count
the key-steps of each algorithm, which are:
- comparison of two elements
- data exchange (note that an exchange normally requires three moves!)
Now write a program 'SortComparison' that compares the algorithms:
- Provide arrays for 50 results for each algorithm
- Do 50 times:
-create a random array of 500 integers
-sort it using Bubble Sort
-store the number of key-steps in the result-array, compute the number of key-steps K by: K=comparisons + 3*exchange
- Do the same for selection sort.
- You got 2 arrays, containing the numbers of key-steps used. Now sort these arrays.
-
Create the top 100 list by merging the result lists. Please merge them in a 100 x 2 String-Array,
containing the result in the first column, the algorithm's name in the second column.
- Look at the top 100 and decide which algorithm was faster.
Example:
Assume the following result lists:
Bubble Sort: 34 56 89 98 ...
Selection Sort: 12 14 37 99 ...
The top 100 will then start like:
12 Selection
14 Selection
34 Bubble
37 Selection
56 Bubble
...
Total Score: 10 points
Go for a bonus point by adding Quick-Sort to the competition ! Again you may use the source of the textbook !
Good luck !