Merge sort

An algorithm that works by dividing a list into smaller sublists until each sublist is a size of 1 and then merging sublists together until everything is sorted. This has the optimal worst/average/best time complexity for any comparison-based sorting algorithm.

Pros Cons
Optimal time complexities Requires linear space
LeetCode Problems
Merge Intervals
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

Performance
Worst-case O(nlog n)
Average O(nlog n)
Best-case O(nlog n)
Worst-case space O(n)

Similar