7.12. Programming Exercises

  1. Using a random number generator, create a list of 500 integers. Perform a benchmark analysis using some of the sorting algorithms from this chapter. What is the difference in execution speed?

  2. Implement the bubble sort using simultaneous assignment.

  3. A bubble sort can be modified to “bubble” in both directions. The first pass moves “up” the list, and the second pass moves “down.” This alternating pattern continues until no more passes are necessary. Implement this variation and describe under what circumstances it might be appropriate.

  4. Implement the selection sort using simultaneous assignment.

  5. Perform a benchmark analysis for a shell sort, using different increment sets on the same vector.

  6. One way to improve the quick sort is to use an insertion sort on lists that have a small length (call it the “partition limit”). Why does this make sense? Re-implement the quick sort and use it to sort a random list of integers. Perform an analysis using different list sizes for the partition limit.

  7. Implement the median-of-three method for selecting a pivot value as a modification to quickSort. Run an experiment to compare the two techniques.

You have attempted of activities on this page
Next Section - 7.13. Glossary