3.7.1.2 Selection Sort
Algorithms and Problem Solving
Selection Sort is another simple sorting algorithm. It works by selecting the smallest (or largest, depending on the desired order) element from the unsorted part of the list and swapping it with the first element of the unsorted part. This process is repeated for the remaining unsorted portion of the list.
Process:
- Find the minimum element in the unsorted part of the list.
- Swap it with the first unsorted element.
- Move the boundary of the sorted and unsorted sections by one element.
- Repeat the process for the remaining elements.
Example: For the list [29,10,14,37,13], Selection Sort will first find the smallest element, 10, and swap it with 29. The list becomes [10,29,14,37,13]. The process continues until the list is fully sorted.
Complexity: The time complexity of Selection Sort is O(n²). Like Bubble Sort, it is not efficient for large datasets but is straightforward to implement.