Gist / June 28, 2023 / 1 min read / By Mahi Garg

Selection Sort : Swift

Selection sort is a sorting algorithm in Swift that works by repeatedly finding the minimum element from the unsorted portion of an array and swapping it with the element in the correct position. This process is iterated until the entire array is sorted. While simple to understand and implement, selection sort has a time complexity of O(n^2), making it inefficient for large data sets. However, it has the advantage of having a minimal number of swaps, which can be beneficial in certain memory-constrained scenarios.