![]() |
VOOZH | about |
Quick sort first partitions the array and then make two recursive calls. Merge sort first makes recursive calls for the two halves, and then merges the two sorted halves.
The following are differences between the two sorting algorithms.
| Basis for comparison | Quick Sort | Merge Sort |
|---|---|---|
| The partition of elements in the array | The splitting of a array of elements is in any ratio, not necessarily divided into half. | In the merge sort, the array is parted into just 2 halves (i.e. n/2). |
| Worst case complexity | O(n^2) | O(n log n) |
| Works well on | It works well on smaller array | It operates fine on any size of array |
| Speed of execution | It work faster than other sorting algorithms for small data set like Selection sort etc | It has a consistent speed on any size of data |
| Additional storage space requirement | Less(In-place) | More(not In-place) |
| Efficiency | Inefficient for larger arrays | More efficient |
| Sorting method | Internal | External |
| Stability | Not Stable | Stable |
| Preferred for | for Arrays | for Linked Lists |
| Locality of reference | good | poor |
| Major work | The major work is to partition the array into two sub-arrays before sorting them recursively. | Major work is to combine the two sub-arrays after sorting them recursively. |
| Division of array | Division of an array into sub-arrays may or may not be balanced as the array is partitioned around the pivot. | Division of an array into sub array is always balanced as it divides the array exactly at the middle. |
| Method | Quick sort is in- place sorting method. | Merge sort is not in - place sorting method. |
| Space | Quicksort does not require additional array space. | For merging of sorted sub-arrays, it needs a temporary array with the size equal to the number of input elements. |