People have learned that after seven weeks in this cs330 class, and a few semesters at IIT, you're good at discrete mathematics and programing, and in need of money too. Therefore the **Silver Bullet Corporation** (CBO) is asking you to help them as a computer consultant. The company has recently lost their programmer, and they need some help in assessing some sorting programs written by the nephew of the company's president. The mentioned nephew is himself a Compuer Science student at a large University in the Chicagoland area.

The problem description is included on the attached memorandum from CBO.

- A well commented listing of the C programs that do the sorting.
- Timing from the programs runs for array sizes of 100 to 2000 in steps of 100
- for each program you will asses the sorting time for the case when the array is already sorted, when it is sorted in reversed order, and when the array's elements are random (this should give us the average performance)
- for each array size you'll run the program 5 times; include the results in a table and also include the average run-time for each array size
- plots of the average running time versus the array size; you can use a linear scale or a semi-logarithmic one

- A memo with your assesment of the problem. In one or two paragraphs indicate what growth function best characterizes the time growth of the sorting algorithms in the average case; do this also for the cases when the arrays to be sorted are sorted or sorted in reversed order. Direct the memo to Mr. Bigan.

- Use the the clock() function that comes with timer.h
- Don't turn in running times of zero! They do not mean we can sort small arrays in no time (though we'd like to): the fact is caused by the
*granularity*of the computer's timer. If the sorting is very fast we may not accumulate at least one CLK_TCK of time. The solution is to perform several sorting iterations, measure the time, and divide it by the number of arrays sorted. In doing so you'll have the trouble of generating random numbers inside the timer loop; since we don't want to include the random number generation time in the sorting time, you will have to take care of this and subtract the generation time from the sorting time. - Don't include the print statements in the timing: we're only concerned with the sorting performance.

**DATE:** October 5, 1995

**TO:** Bob Bigan, Director R&D

**FROM:** John Clyde

**SUBJECT:** Basil's Sorting Algorithms

I am unpleasantly surprised to learn that our programmer has left SBC. I find disturbing that we can not keep programmers with our current competitive wage of $4.36 per hour. This resignation comes at a very difficult time, since I am interested in implementing the sorting algorithms developed by my nephew Basil. We need to assess the algorithms before we put them in production mode. Hire a consultant if necessary to complete the task.

The question to be answered is: "What is the growth rate (with respect to time) of Basil's sorting algorithms?". Since the growth rate of our currently used sorting algorithm is cubical, anything better than that will be good for us.

Your help in this matter is highly appreciated.

**DATE:** October 1, 1995

**TO:** Bob Bigan, Director R&D

**FROM:** Mike Donald, Programmer

**SUBJECT:** Basil's Sorting Algorithms

Since I am leaving the company, I want to pass on some information concerning the sorting programs developed by Mr. Clyde's nephew Basil.

The programs are written in C and utilize sorting algorithms I am not familiar with. I have implemented Basil's code and it seems to be sorting arrays properly.

Basil's work consists of the following:

*mystery1()*and*mystery2()*are sorting functions*vector()*allocates spaces in memory for the array to sort*free_vector()*frees the memory space occupied by the array

I did start program modifications to assess the timing of the programs. However, I haven't had time to complete my work. I've attached a copy of the code as it currently exists. A zip-ed version also exists and you can download it if your web browser can.

It seems like Mr. Clyde wants to know what the time growths of the sorting programs is . He would like the algorithms assessed for array sizes of 100 to 2000 in steps of 100. Once these timings are complete he would like the results compared to the standard growth functions (constant, logn, n, nlogn, n^2, n^3, 2^n) and a determination made as to which growth rate function the sorting algorithms follow.

Should there be any questions on the programs, you can contact me at my new employer Donalds.

Sincerely,

This programming assignment has been inspired by Chuck Pheatt.