Heapsort

This algorithm works by inserting every element into a heap and then removing them one by one to get them in sorted order. This is slower than quicksort on average but has a better worst-case time and can be done in-place compared to the linear space required by merge sort.

Pros Cons
Optimal worst/average/best time performances Slower than quicksort on average
Can be done in-place Requires a heap
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