CS209 lab3
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l3.html
-
For this lab you should submit all source code (C
files), and the result(s) of running the program on (a few)
test cases.
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code).
-
The above material should be uploaded to BLACKBOARD
before
the deadline of 5pm
Wednesday 16th. February 2011. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/
Consider the QUICKSORT and MERGESORT algorithms covered in lectures, with code
at
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/
-
Build a new hybrid recursive algorithm, that calls quicksort
and mergesort alternately. So, say, first time around
quicksort is called, and this function will then call two copies of
mergesort, which then calls quicksort, etc. (with of course
successively decreasing sizes of the arrays).
Your program will have to have two recursive functions.
You could base the alternation on whether the array size is even
or odd (e.g. for even call mergesort, for
odd call quicksort).
-
Adapt your code as follows. In quicksort, when we split about the
pivot, the two new (smaller) arrays in general are not of equal
size, in some cases one may be much larger than the other.
In your code, if one (either) of the smaller arrays is 80% or more
of the original array size, then for that array, call
mergesort.
For smaller arrays that are less than or equal to 80% of the original
size, call
quicksort
again.
(In the mergesort function, the recursive call will
remain to quicksort in all cases).
©
NUI, Galway