You may use a STL container class for your bins. (Or you
may implement your own list class if you wish)
You may add a constant to the program that indicates the maximum
number of digits in any number
If MAXVALUE stays at 1000000, MAXDIGITS is 6
Or you may calculate this if you wish (ceil (log (MAXVALUE)) )
Do we have a better sort?
Run the program with a number (5 or more) of different input sizes
If you just add Sort(5, array, arraysize) after Sort(4,...) in
the main program
sorts -as n -4
will run sort 4 and sort 5 only
Depending on the compile options, and machine, you will have to
find a size for n where the routines take sufficient time for
the time routine to be able to report any time used.
Which sort is better? Do we have a mistake in our analysis?
swaps & compares
Add global variables moves, compares
I know you were told never to do this, but we are performing
an experiment, not writing usable code.
add the line
int moves, compares;
under the line
const int MAXVALUE=1000000;
const int MAXDIGITS = 6;
In the Sort routine, initialize each to 0 when the start time is set
In the Sort routine, print out the value of
compares and moves
along with the time for the sort. Make sure you label these.
In each routine, add one to the compares variable each time a
comparison is made
What is a reasonable measure for comparison in radix/bin sort?
In each routine add one to the moves value each time an item
is moved into or out of an array position
Don't count accesses for compares (if (array[i] < array[j]) does not count as a move)
array[i] = x counts as one
x = array[i] counts as one
So a swap should count as 3
Only count assignments within the sort* routines,
(not in fillit or CopyIt)
Run a number of trials and compare the number of moves and comparisons
each sort performs.
Consider only the improved selection sort (sort2), quicksort and radix/bin sort.
perform 10 trials each for each power of two between 210
and 215.
For n=210 (1024), run each sort 10 times,
You should call fillit for each new trial, but run
all three sorts on each set of data.
sum the number of moves/compares for each run
in the end, divide the sum by 10 and print it out for each
sort.
I did this by adding a loop to the main program beginning
after the new ending before the return. I also
added an array, that stored the total number of
compares/moves for each sort.
Record the average number of moves for each sort
You probably want to optimize your code when you compile it
for this portion of the homework.
g++ -o sort -O3 sort.C
Write a lab report summarizing your results.
Write a intraductory section discussing the sorts (a one or two sentence summary of the algorithm for each) and a table comparing the average and worst case asymptotic analysis for each. Describe the space required by each sort.
Each of the following sections should include tables of results,
graphs of results and a narative.
A section on timing. (focus on quicksort vs radix/bin sort, but
include the other sorts as well)
A section on number of comparisons each sort performs. (Focus on radix/bin, quick and improved selection sorts, but mention all sorts)
A section on number of moves each sort performs. (Focus on radix/bin, quick and improved selection sorts, but mention all sorts)
Other authors suggest a valid measure for sorting performance would
be to compare the number of moves or the number of comparisons
each sort performs. Write a section of your report that critisizes/supports this. Give examples.
Write a conclusion. Discuss
Which sort would be appropriate for best time performance.
Which sort would be appropriate if comparisons were very expensive.
Which sort would be appropriate if moves were very expensive.
Which sort you consider best overall.
Your observations, and anything that supprised you when
performing this lab.
Any suggestions for further experimentation with these sorts.