AP® Computer Science A glossary
Selection sort
Course: AP® Computer Science A Shows up in: Unit 4: Data Collections
An iterative sort that repeatedly selects the smallest (or largest) unsorted element and swaps it into its final position.
Appears in the course and exam description (CED): 4.15.A.14.15.A.2
Each pass of selection sort scans the unsorted portion for its minimum and swaps it to the end of the sorted portion. That position is final. For n elements it always makes n(n - 1) / 2 comparisons, whatever the starting order.
Example
// {29, 12, 41, 7} after each pass:
// pass 1: {7, 12, 41, 29}
// pass 2: {7, 12, 41, 29}
// pass 3: {7, 12, 29, 41} Learn it properly, with a checkpoint 4.15 Sorting Algorithms