Selection Sort Algorithm

Selection Sort is a simple sorting algorithm that divides the list into two parts: a sorted part and an unsorted part. The algorithm repeatedly selects the smallest (or largest, depending on the order) element from the unsorted part and moves it to the end of the sorted part. This process continues until the unsorted part is empty.

Algorithm

1. Start with the first element as the minimum.
2. Compare this minimum element with all other elements.
3. If a smaller element is found, update the minimum.
4. Swap the minimum element with the first element.
5. Move the boundary of the sorted part one position forward.
6. Repeat the process until the entire list is sorted.

Time Complexity

Best Case: O(n²)
Average Case: O(n²)
Worst Case: O(n²)