- **Key idea**:
+ Repeat the following until it is sorted:
+
Look through the collection to find the **smallest**
+
Move that element to the **beginning** of the unsorted region of the list
![selection sort animation](https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif)
## Docstring for Sort
```py
def selection_sort(lst):
"""Sorts lst so that its elements are in ascending order
Parameters:
lst: a list
Returns:
Nothing; just modifies lst
Preconditions:
* for all elements x,y in lst,
x < y is defined
Postconditions:
* lst is reorganized in increasing order, i.e.,
lst[i] <= lst[i+1]
holds for all reasonable values of i
* no elements are added or removed from lst"""
```
# Implementation of Selection Sort
- [selection_sort.py](/teaching/2021s/cs65/assets/code/selection_sort.py)
## Selection Sort Visualization