Lab 7 - Basic Sorting Algorithms

Due: 5:00pm on Wednesday

The purpose of this lab is to trace through selection and insertion sort on paper so that you can be familiar with how they operate.

There is no coding for this lab. Answer the following questions. You can send me an email with your answers (use plain text, Open Office or PDF format) or turn in a hand-written answer.

  1. (6 points) Sort the array 59, 24, 10, 45, 78, 32, 29, 63, 82, 95 using the following algorithms. Show all work as specified by each algorithm.
    1. Selection sort. Show each pass (where slot i is replaced with the minimum of slots i through the end of the array).
    2. Insertion sort. Show each pass (where a hole is opened up in elements 0 through p-1 to insert the p-th element).
  2. (4 points) One modification of insertion sort that is useful for sorting large objects is to sort an index table instead of the actual array. An index table contains the index number of the smallest element in slot 0, the index number of the second smallest element in slot 1, and so forth. For example, the index table for the array 15, 78, 25, 11 would be 3, 0, 2, 1.
    Give the pseudocode for a modified insertion sort that sorts an index table instead of the actual array. Use the variable name "index" for the index table and "array" for the actual array. (Hint: All less-than comparisons will use syntax similar to "array[index[i]]" to access the actual value while all of the sets will use syntax similar to "index[i]" to alter the index table)