Member-only story
Selection Sort in Swift
The classic
Difficulty: Beginner | Easy | Normal | Challenging
This article covers the classic sorting algorithm Merge Sort, and it’s implementation in Swift.
- This is seen as a beginner topic (first year Computer Science degree fare) but is certainly not easy.
Terminology
Algorithm: A process or set of rules to be followed
Big O Notation: A mathematical notation to describe the limiting behaviour of a function when an argument tends towards infinity
Selection Sort: An implementation of linear search, where the smallest element is placed sequentially to the front of the list
Selection Sort
The simple theory
A selection sort is about performing a linear search, placing the smallest element sequentially at the front. Since are are performing a linear search for (potentially) every item in the list we are looking at a O(n²) worst case scenario for time complexity.