Sorting


The sorting problem: Given a sequence A1, A2 ,..., An of integers, find the sorted sequence B1, B2 ,..., Bn consisting of the same set of integers ordered so that:

B1 < B2 < ... < Bn

Sorting is one of the most fundamental problems in computer science, and many sorting algorithms are known.

We develop a simple algorithm called selection sort that can be extracted directly from the problem description.

The Selection Sort Algorithm **

Stage 1: Find the largest item in the list and move it to the end (usually by exchanging the current end item and the largest)

Stage 2: Repeat stage 1, reducing the length of the list by one element each time through, until the length of the new list is exactly 1.


** Identify the elements of problem solving in this algorithm

[Prev][TOC][Next]

CS1104 Main Page
Last Updated 2002/02/01
© L.Heath, 2000, upgraded by J.A.N. Lee on above date.