1,003 views
0 votes
0 votes
I did Google and found out that Quicksort is better then Mergesort, but my question is which is faster among both?

2 Answers

1 votes
1 votes

Quicksort gives worst-case performance (i.e. O($n^2$) ) when the array is already sorted or almost sorted.In best case and average case quicksort takes O(nlogn) time . 

Time complexity of Merge Sort is O(n*Log n) in all the 3 cases (worst, average and best) as merge sort always divides the array in two halves and takes linear time to merge two halves.

So based on cases in which you use these sorting algorithm each has its own benefit.

But when comparing the worst case performance of both algorithm merge sort is better .

0 votes
0 votes

If the input contains random elements (i.e, not sorted, nearly sorted or same elements) then quicksort gives better performance than merge sort as though they have same best case time complexity Θ(n.logn) but quicksort runs faster by the constant factor which we ignore during asymptotic analysis.

Merge sort needs to copy the elements to another array which take extra time.

For more explanation, you may refer to this video

Related questions

1 votes
1 votes
1 answer
1
8 votes
8 votes
2 answers
2
1 votes
1 votes
3 answers
3
Angkit asked Apr 23, 2017
14,549 views
Which sorting algorithm can be used to sort a random linked list with minimum time complexity ?A)mergesortB)quicksortC)radixsortD)insertionsortE)heapsort
1 votes
1 votes
1 answer
4
Purple asked Jan 27, 2016
24,737 views
If the number of records to be sorted is small, then ...... sorting can be efficient.A. MergeB. HeapC. InsertionD. Bubble