Merge Sort is a popular sorting algorithm that follows the divide and conquer approach. The algorithm works by breaking down the list into smaller sub-lists and sorting them individually.
These sorted sub-lists are then merged back together to obtain the final sorted list.
Time & Space Complexity
Merge sort is a divide and conquer algorithm, it has a logarithmic time complexity of O(n log n)
Merge sort's space complexity is O(n)
What is a merge sort?
Steps of Merge Sort
Divide the unsorted list into smaller sub-lists until each sub-list contains only one element.
Repeatedly merge adjacent sub-lists to produce new sorted sub-lists until there is only one sub-list remaining. This is done by comparing the elements of the sub-lists and merging them in the correct order.
The final sorted list is obtained when all sub-lists are merged.