Merge sort

Merge sort is a divide and conquer algorithm that has a lower order running time than the insertion sort. The merge sort algorithm works by using recursion; it will repeatedly divide an unsorted list into two halves. When the list has a single item or it is empty it is considered sorted; this is called the base case. The majority of the sorting work is performed in the merge function, which is responsible for combining the two halves back together. The merge function uses a temporary array of equal size to the input array during the merge process so it has a higher order auxiliary space of O(n). Because of this, merge sort is generally better off implemented for sorting a linked list instead of an array. We'll look at both implementations ...

Get Swift Data Structure and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.