in Algorithms
993 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?
in Algorithms
by
993 views

4 Comments

Quick sort is faster in some cases, but not all cases.

In case of performence, we have to check if it is best, average or worst case performence
1
1
thanks.
0
0
when we have large data set then which one to use and why ?
0
0
Quick sort and Merge sort both can handle large data set. As both uses divide and conquer rule.
0
0

2 Answers

1 vote
1 vote

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 .

1 comment

thank you.
0
0
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 vote
1 vote
1 answer
1