Selection Sort
This is the worst algorithm, but it is introduced in every class.
High Level Idea:
- Find the smallest element of array
- Swap with the first element of array
- Repeat with the rest of the array, looking for the second smallest element and swapping with the second element
Selection Sort Pseudocode
A is the name of the array
Time Complexity
This algorithm is bad because no matter the case, even when the array is sorted, we need to go through every element twice.
- Best Case Sort:
- Average Case Sort:
- Worst Case Sort:
Space Complexity
- Worst Case:
Better algorithms: