1.

Differentiate between quick sort and merge sort in the context of sorting algorithms.

Answer»

 Following are the DIFFERENCES between quick sort and merge:

Quick SortMerge Sort 
In a quick sort, the array is DIVIDED into any ratio. In a quick sort, there is no requirement to divide the array of components into equal sections.The array is divided into only two halves (i.e. N/2) in the merge sort.
The WORST-case complexity of quick sort is O(n2)In merge sort, the worst and average cases have the same complexity O (n log n).
The quick sort, on the other hand, does not function well with large datasets.Merge sorting can be used on any form of data set, regardless of its size (either large or small).
The quick sort is in place since it does not necessitate any extra storage.Merge sort is not in place because it requires additional memory space to hold the auxiliary arrays.
Quick sort is unstable (two elements with the same value may appear in a different order in the sorted array from that in the unsorted input array) in this situation. However, with a few code tweaks, it may be made stable.Merge sort is stable because two elements with the same value appear in the sorted output in the same order as they did in the unsorted input array.
Quick sort is preferred for arrays.Merge sort is preferred for linked lists.
Quicksort has a good cache locality, making it faster than merge sort (in many cases like in a VIRTUAL memory environment).Merge sort has a poor locality of reference.


Discussion

No Comment Found