Time and Space Complexities
- Time Complexity: Merge sort has a time complexity of O(n log n) in the worst-case scenario. This is because it divides the array into halves recursively and merges them in linear time.
- Space Complexity: Merge sort has a space complexity of O(n) due to the need for auxiliary space for merging the sub-arrays. However, in practice, it’s often considered out-of-place, meaning it requires additional space proportional to the size of the input array.
How to use Merge Sort with TypeScript ?
Merge sort follows the divide and conquer approach, which means it breaks the problem into smaller sub-problems, solves each sub-problem, and then combines the solutions to solve the original problem.