ABSTRACT

Selection Sort is an in-place comparison sorting algorithm. It works by dividing the input list into two parts: a sorted sublist which is built up from left to right, and an unsorted sublist. In each step, it selects the smallest element from the unsorted sublist and swaps it into the next available position in the sorted sublist.


The Strategy

For a list :

  1. Scan: Search the unsorted portion of the list for the smallest element .
  2. Swap: Exchange with the element at the beginning of the unsorted portion.
  3. Repeat: Move the boundary of the sorted portion one element to the right and repeat until the entire list is processed.


Efficiency Case Studies

1. Which list requires the fewest swaps?

  • Sorted List: If the list is already in order, the algorithm identifies that the element already at the current index is the minimum.
  • Result: swaps.

2. Which list requires the greatest swaps?

  • Cyclically Shifted: If the list is shifted (e.g., ), the algorithm must perform a swap at nearly every step.
  • Result: swaps.

Time Analysis

On a list of length , Selection Sort is characterized by its predictable comparison count but highly efficient swap count.

1. Number of Swaps

  • Best Case:
  • Worst Case:
  • Big-O: This makes Selection Sort superior to Bubble Sort in scenarios where write operations (swaps) are expensive.

2. Number of Comparisons

Unlike Bubble Sort, Selection Sort always performs the same number of comparisons because it must scan the entire unsorted portion to guarantee it has found the true minimum.

  • Formula:
  • Big-O: for both Best and Worst cases.

Pros and Cons

StrengthsWeaknesses
Minimal Swaps: Performs at most swaps.Unstable: May swap equal elements out of their original relative order.
Memory Efficient: In-place algorithm ( extra space).Inefficient Comparisons: Does not “notice” if a list is already sorted ( even in best case).