CS209 lab3


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l3.html




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/

  1. 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).
  2. 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