Merge Sort
Merge Sort: Introduction
The idea of merge sort is to divide the array into two halves and then merge them in a sorted manner. The merge sort is a recursive algorithm. The base case is when the array has only one element. The recursive step is to divide the array into two halves and then merge them in a sorted manner. The merge step is to compare the elements from left and right sub-arrays and then put the smaller element in the sorted array. The merge step is repeated until the two sub-arrays are empty.
Merge Sort: Implementation
Merge Sort: Big O
The time complexity of merge sort is O(n log n). It is the most efficient sorting algorithm. The space complexity is O(n).
Last updated