my head

Selection Sort ↔️

Back to algorithms list.

Functionality

Selection Sort is a simple comparison-based sorting algorithm that sorts a list by repeatedly selecting the smallest (or largest) element from the unsorted portion and moving it to its correct position in the sorted portion. The algorithm works by dividing the list into two parts: a sorted portion at the beginning and an unsorted portion at the end. It iterates through the unsorted section, finds the minimum element, and swaps it with the first unsorted element. This process continues until the entire list is sorted.

Advantages

  1. Simplicity: The algorithm is easy to understand and implement, making it ideal for teaching basic sorting concepts.
  2. In-place Sorting: Selection Sort does not require additional memory as it sorts the list within the original array.
  3. Fewer Swaps: Compared to algorithms like Bubble Sort, Selection Sort performs fewer element swaps, as each element is swapped at most once.

Disadvantages

  1. Slowness: The algorithm has a time complexity of O(n²) for both average and worst cases, making it inefficient for large datasets.
  2. Unstable: Selection Sort is not a stable algorithm, meaning it can change the relative order of elements with equal values.
  3. I Inefficiency on Nearly Sorted Data: Even if the list is nearly sorted, Selection Sort continues to make unnecessary comparisons.

Conclusion

Selection Sort is a simple and intuitive algorithm, useful for small datasets or when memory usage is a concern. However, its inefficiency on large datasets and lack of stability limit its practical use in many real-world applications.

Source: Article about selection sort on wikipedia.org