DUE DATE: 12/12/01 (60 points)
Data[ ] = [30, 62, 7, 35, 90, 19, 38, 79, 24, 11, 43]
shiftdown(int data[], size_t pos, size_t n) Shift the element in data[pos] down through the heap of size n until the heap constraint is satisfied. shiftup(int data[], size_t pos, size_t n) Shift the element in data[pos] up through the heap until the heap constraint is satisfied.
Cars are to be stored in an vector V. To simplify queries about
the spatial relationships among cars, this array must be maintained in
sorted order based on car mileage (i.e. distance from the starting line.)
On each step of the simulation, car mileage is updated and the array must
be re-sorted. It is important that the sorting time be as small as possible.
You must compare two sorting methods: the standard template library sort function and an insertion sort function that you must code. Your assignment is to assess run times for the two sorting methods under the condition that adjacent values change order with some probability p. The vector to be sorted, V, will contain integers. Initially, create a sorted vector by setting V[i] = i. Then jumble the vector by swapping adjacent values with probability p. You should consider three values of p ( .001, .01, and .1) and six different vector sizes (10, 50, 100, 500, 1000, 5000). A demonstration program is available here.
The Unix operating system provides a useful means to measure execution time through the time command:
%time command
This statement will print a report on the execution time and system resources used to run the command command. The exact form of the report varies across our Unix platforms. You should read the manual page on your machine for a description of the output format. You should compare user times in your assessment.
The precision with which time is measured also depends on the the machine you use. The accuracy is no worse that 100Hz. This means that you cannot accurately measure the execution time for commands that take less that .01 seconds to run. To be sure that your error is less that 5%, the time to execute a command must be greater than .20 seconds. This means that you must repeatedly sort small vectors until the total sorting time is greater than .20 seconds. You must then divide the total time by the number of times the vector was sorted.