Sunday, November 3, 2019

Algorithm: Difference between Quick Sort and Merge Sort


1. Merge Sort is stable sort however Quick is not.
2. Worst case complexity for merge is O(nlogn) however for quick it is o(n*n)
3. Merger requires O(n) extra space for merging, however Quick does in place sorting.
4. Merge works well with all sizes of array, however Quick is good for smaller arrays for larger arrays it is inefficient as it does lots of comparison.
5. The Quick is internal nature means sorting happens in memory however Merge sort happens in auxiliary space i.e. it is external in nature.

Quick sort example



Merge sort example

No comments: