CS 305-503, Data Structures & Algorithms

Quiz 1, 11 November 2008


  1. What's the difference between mergesort and natural mergesort?


    See Nyhoff, page 766.

    The answers, in no particular order and approximately verbatim:

  2. A colleague of yours wants to improve insertion sort by using a binary search. How much improvement do you expect from the modified insertion sort over the unmodified one? Explain.


    Not much. Using a binary search to locate x in the sorted part of the array uses O(log n) comparisons as opposed to O(n) in the unmodified insertion sort and so should be faster. However, once located, it's still necessary to shove the sorted elements to the right one, which takes O(n) work in either case.

    The answers, in no particular order and approximately verbatim:

  3. What happens in a radix-exchange sort if the numbers are sorted from right to left?


    The sort doesn't. Sorting from the least- to most-significant digits moves adjacent values to separate piles and may never reunite them. For example, the standard (left-to-right) radix-exchange sort would group 101 and 103 in the same pile (the 100s pile), while the right-to-left sort would put them in separate piles (the 1s and 3s piles) where it is likely they will never be brought into proximity again.

    The answers, in no particular order and approximately verbatim:

  4. The quicksort partition discussion didn't pay any particular attention to array elements that equaled the pivot. What kind of special action, if any, do you think partitioning should take when it finds an array value that equals the pivot? Justify your answer.


    It should group equivalently-valued array elements with the pivot and split the array at the ends of the block. This would (may, because duplicate pivot values are not guaranteed) reduce the number of times the quicksort algorithm recurses over the array halves because the halves are smaller.

    quicksort partitioning

    Alternatively, grouping the values equal to the pivot at the pivot places them in the array at their final locations in the sort, and there's no need to consider them further.

    The answers, in no particular order and approximately verbatim:


This page last modified on 12 November 2008.