1. Mergesort vs Quicksort
In Depth Analysis
Presented By
Maharaj Dey 11500117099
and
Sandeep Kumar 11500117059
2. Why quicksort is better than mergesort ?
This a common question asked in DS interviews
that despite of better worst case performance of
mergesort, quicksort is considered better
than mergesort.
5. 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(n2) O(nlogn)
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
Comparison
6. There are certain reasons due to which quicksort is better especially in case of arrays:
Auxiliary Space : Mergesort uses extra space,
quicksort requires little space and exhibits good
cache locality. Quick sort is an in-place sorting
algorithm. In-place sorting means no additional
storage space is needed to perform sorting. Merge
sort requires a temporary array to merge the
sorted arrays and hence it is not in-place giving
Quick sort the advantage of space.rge sort.
Locality of reference : Quicksort in
particular exhibits good cache locality and
this makes it faster than merge sort in
many cases like in virtual memory
environment.
Worst Cases : The worst case of
quicksort O(n2) can be avoided by using
randomized quicksort. It can be easily avoided
with high probability by choosing the right pivot.
Obtaining an average case behavior by choosing
right pivot element makes it improvise the
performance and becoming as efficient as
Merge sort.
Merge sort is better for large data
structures: Mergesort is a stable sort, unlike
quicksort and heapsort, and can be easily
adapted to operate on linked lists and very large
lists stored on slow-to-access media such as disk
storage or network attached storage.