Project 2 Discussion
The following are clarifications and further discussion on Project 2. Many of these items were generated based on questions received during lectures and in e-mails to Mr. Kukla and Ms. Mitchell. Check this page frequently to keep informed!
- For merge sort, count the move of an array element into the temporary array or into the original array as a swap.
- See the on-line manual for information on using the C/C++ random number generator (Type: man rand).
- If you feel that you need to make any changes or additions to the private section of the SortMetrics class, see your instructor for guidance. Some changes/additions might be justified, but for others there may be a simpler solution.
- You do not need to comment any code that has been provided for you (e.g., the sorts, SortMetrics.H). However, you MUST cite the source where you got the code. (Points may be deducted if you do not.)
- You will be formatting your output for this project. Look at the
setw
and setprecision
stream manipulators in your book. There may be other stream manipulators that are useful as well. Don't forget to #include
the iomanip.h
header file.
- The choice of either random or sorted for the input array is necessary because the same sort may yield a different Big-Oh depending on the initial ordering of the array elements.
- When generating a sorted input array, fill it in ascending order.
- When generating a random input array, keep the values <= the maximum size of an
int
. Duplicate values may occur, which is fine.
- Make sure the line in your makefile that actually generates the executable
(the line that links the .o files together) ends in
-lm
(that's
"dash ell em") to link in the math library. Failure to do this will result
in "unresolved" errors from the linker that ask for definitions of
functions like log.
- When computing
n*n
, use code like: n*(double)n
and store the result into a double
. This eliminates the
problem of n squared growing so rapidly that your program generates invalid
results for very large sizes of n. Your program need only support array
sizes as large as the sample program does (number coming soon) but you may NOT
hardcode the maximum array size into your program to avoid allocating an array
of the correct size for each run.
Last Modified: