Homework Assignment #3, CISC 320, Spring Y2K

Due Friday, March 10.

Some of this homework involves working with files in the composer directory

/home/base/usrc/40/16603/public_html/320/

aka

~saunders/320/

You may find it convenient to make a link to this directory from your own, thus:

ln -s ~saunders/320 320dir

After this link is established, it will be as if the subdirectory named 320dir (or whatever name you choose for it) of your current directory is the directory ~saunders/320/. However, you will have only read and execute access to this directory (no write access). Any files you want to modify, you must copy to another place.

  1. How deep?
    CLR Exercise 9.1-1
  2. What is the "constant" factor?
    Our analysis predicts that quickSort runs in expected time C*n*lg(n), for some constant C. The point of this exercise is to estimate the constant C and see how well a few experimental measurements with specific random choices conform to the overall expected formula.
    1. Run quickSort on a 100,000 element array of record references several times with different random seeds. For example:

      time ~saunders/320/quick 100000 12345

      where 12345 is the random seed you've chosen for that run.

    2. Make a table of the random seeds you used and the corresponding run time (user time in seconds).
    3. In a third column of your table, put the corresponding estimate of C. See ~saunders/320/times.mpl for an example of computing C.
      Indicate the units of C (in file times.mpl it is microseconds).
    4. Compute the average of the C's corresponding to the different runs you did. How varied are the C's? Write a comment or two about this such as "very consistent" or "wildly varying" or "consistent with a few outliers" or ...
    5. Consider the number n = 524288, which is 2**19. Thus lg(n) is exactly 19. Using the formula C*n*lg(n), estimate the time quickSort will take on an array of size n. Run time ~saunders/320/quick 524288 (with or without a random seed, as you wish) and report how well the user time conforms to the prediction.
  3. Partial implementation of introspective sort:
    As we saw in class, the standard template library has a sort routine that tends to be faster than any of the sort algorithms in ~saunders/320. It uses heapSort to protect against really bad cases. Let's ignore that part. However it uses insertionSort when the array is small in order to get a performance speedup. In this exercise do
    1. Make a copy of quickSort.h, and modify it to use insertionSort on small arrays. Experiment with different threshold sizes for the use of insertionSort.
    2. Report the relative speeds of
      1. quickSort (you can use the already compiled executable "quick"),
      2. stl's sort (you can use the already compiled executable "stl"), and
      3. your modified quickSort, with your best threshold value.
      (Include a printout of the code in your submission.)

    saunders@cis.udel.edu