Member-only story
Merge Sort in Swift
The classic sorting algorithm
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
Merge Sort: A sorting algorithm where an array is split into to, sorted and merged back together.
Merge Sort
The merge sort algorithm is a nice algorithm for sorting an array.
The algorithm
Setting up tests
Using the playground, inserting import XCTest
and allowing the tests to be run using sortingTests.defaultTestSuite.run()
allows us to create tests before creating the solution in Swift.