Quick Sort Vs Merge Sort [duplicate]
Solution 1:
See Quicksort on wikipedia:
Typically, quicksort is significantly faster in practice than other Θ(nlogn) algorithms, because its inner loop can be efficiently implemented on most architectures, and in most real-world data, it is possible to make design choices which minimize the probability of requiring quadratic time.
Note that the very low memory requirement is a big plus as well.
Solution 2:
Quick sort is typically faster than merge sort when the data is stored in memory. However, when the data set is huge and is stored on external devices such as a hard drive, merge sort is the clear winner in terms of speed. It minimizes the expensive reads of the external drive and also lends itself well to parallel computing.
Solution 3:
For Merge sort worst case is O(n*log(n))
, for Quick sort: O(n
2)
. For other cases (avg, best) both have O(n*log(n))
. However Quick sort is space constant where Merge sort depends on the structure you're sorting.
See this comparison.
You can also see it visually.