Data Structures & Algorithms
CS 305 & 503

Quiz 3, 24 November 2009


  1. Explain how Shell sort generalizes one of the sorts we covered in class.


    See Lafore, page 316.

  2. A colleague of yours suggests it would be easier to compute the median-of-three pivot value using the first three elements of the array segment passed to partition(). What is your opinion of your colleague’s idea?


    Using the first three values would be marginally easier than computing the mid-point index value, but it almost completely ignores the point behind using the median-of-three pivot. If the array segment is amost sorted, using three the median of three consecutive values would still leave the pivot towards one end of the segment, driving partition, and so quicksort, into worst-case behavior.

  3. Suppose mergesort is modified to split the data sequence into thirds rather than halves. Give an analysis of the modified mergesort that shows the effect of the change on the algorithm's estimated running time.


    Dividing an array segment into thirds rather than halves effects mergesort’s recursive depth: rather than recursing log2 n levels for an array with n elements, it will resurce log3 n levels. Each level still does the same amount of O(n) work. A three-splitting mergesort does O(n log n) work.

  4. Write in the proper quadrants below the names of the O(n2) worst-case sorts discussed in this section. For example, if sort algorithm X uses O(n) comparisons and O(n2) assignments during a sort, X should appear in the upper-right and lower-left quadrants. Justify your choices.

    q3f1.png


    The O(n2) sorts considered were

    q3f2.png


This page last modified on 30 November 2009.