Selection Sort
Selection Sort is a straight forward sorting algorithm that works by repeatedly selecting the smallest (or largest, depending on the order) element from an unsorted portion of the list and moving it to the beginning (or end) of the sorted portion. Here's how it works step-by-step:
- Start with the first element: Assume the first element is the smallest in the list.
- Find the smallest element: Look through the rest of the list to find the smallest element.
- Swap: If you find a smaller element, swap it with the first element.
- Move to the next position: Now consider the first element as sorted and move to the next element in the list.
- Repeat the process: Repeat the process for the rest of the list until the entire list is sorted.
- Repeat: Keep repeating until you make a pass without any swaps, which means the list is sorted.