Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MergeSort, QuickSort or HeapSort? [closed]

What are are the relative advantages of the three in terms of the number of comparisons performed and the amount of memory required by the algorithms. Which of them is their running time guaranteed?

like image 459
Manuel Avatar asked Dec 19 '13 22:12

Manuel


People also ask

Is heapsort better than mergesort?

The merge sort is slightly faster than the heap sort for larger sets, but it requires twice the memory of the heap sort because of the second array.

Which is faster mergesort or quicksort?

Merge sort is more efficient and works faster than quick sort in case of larger array size or datasets. Quick sort is more efficient and works faster than merge sort in case of smaller array size or datasets.

Which is better heapsort vs quicksort?

Heapsort is typically somewhat slower than quicksort, but the worst-case running time is always Θ(nlogn). Quicksort is usually faster, though there remains the chance of worst case performance except in the introsort variant, which switches to heapsort when a bad case is detected.

What is the advantage of using heapsort over Mergesort?

Advantages of Heap Sort It is efficient for sorting a large number of elements. This implies that no other sorting algorithms can perform better in comparison. Memory usage is minimal. In contrast, the Merge Sort algorithm requires more memory space.


3 Answers

I think Wikipedia's coverage of this is pretty thorough and answers all your questions. The comparison table shows the best, average and worst-case performance, the memory usage, and other characteristics like stability.

like image 81
TypeIA Avatar answered Oct 20 '22 01:10

TypeIA


This is easily answered by looking at Wikipedia...:

http://en.wikipedia.org/wiki/Sorting_algorithm

If you are unsure how to look for the "guaranteed" runtime then you're looking for the worst case.

like image 36
Jakub Kotowski Avatar answered Oct 20 '22 00:10

Jakub Kotowski


If you want a visual explanation, this classic animation film called Sorting Out Sorting was made by a University of Toronto CS group in the 1980s. It is worth the watch, covering the three sort types and scenarios where they work best (and also not so well) — and why.

like image 45
Alex Reynolds Avatar answered Oct 20 '22 00:10

Alex Reynolds