Algorithms and OOD (CSC 207 2014F) : Outlines

Outline 26: An Introduction to Sorting

Held: Monday, 13 October 2014

Back to Outline 25 - Using Java from the Command Line. On to Outline 27 - Quadratic Sorts.


We consider the well-known problem of sorting. Along the way, we consider some issues in testing and object-oriented design.

Related Pages



Upcoming Work

Notes from the Prologues

Extra Credit


Peer Support

Project Planning

Question: In the second half of the semester, you will do a project. There are three possibilities right now.

We'll do a quick discussion and then come back to the question immediately after break.

The problem of sorting

An object-oriented approach

Testing sorters

Sam's favorite permutation algorithm

Here's the algorithm in pseudocode

 // Apply fun to every permutation of values
 useAllPermutations(values, fun)
   useAllPermutations(values, fun, values.length)

 // Apply fun to all permutations of values in which the
 // elements at position pos and higher are not changed
 useAllPermutations(values, fun, pos)
   // Base case: No elements to change
   if (pos == 0)
   // Normal case: Lots of work!
     // Every value has to appear in position pos-1 for some set
     // of permutations
     for i from 0 to pos-1
       // So put it in that position
       // We then need every permutation of the remaining elements
       useAllPermutations(values, fun, pos-1)
       // Swap it back for the next round