This book is now obsolete Please use CSAwesome instead.

13.4. Selection Sort

The selection sort that you need to know for the exam starts at index 0 and looks through the entire array keeping track of the the index of the smallest value in the array and then swaps the value at the smallest index with the value at index 0. Then it does the same thing for index 1, then 2, and so on until it reaches the length of the array minus one. At this point the array is sorted in ascending order.

Here is a folk dance video that shows the selection sort process.

To identify a selection sort look for the following:

The code for selectionSort below is from the AP CS A course description.

To see this executing using the Java Visualizer click on the following SelectionSort

You can step through the code above by clicking on the following Ex-12-4-2.

You have attempted of activities on this page