Difference Between Quick Sort and Merge Sort

Computer ProgrammingProgrammingMiscellaneous

In this post, we will understand the difference between Quick Sort and Merge Sort.

Quick Sort

  • In Quick Sort, the elements need to be partitioned into different parts repeatedly until it can’t be divided further.

  • The array is split into a specific number of parts, in a specific ratio.

  • It is not divided necessarily into exactly half.

  • It is based on divide and conquer strategy.

  • It is also known as partition exchange sort.

  • The worst case complexity is O(n squared).

  • It uses a key/pivot element to sort elements.

  • It works well with small number of elements in an array.

  • It is better than other sorting algorithms since it is quick.

  • It requires less additional space/memory.

  • It doesn’t work well with large number of elements in an array.

  • It is not considered a stable sorting method.

  • It is considered as an internal sorting algorithm.

Merge Sort

  • Merge Sort is considered as an external sorting algorithm.

  • The array is split into two sub-arrays (n/2) where ‘n’ is the number of elements in the array.

  • This is done until only on element is left after splitting the array.

  • It is based on divide and conquer strategy.

  • Its worst case complexity is O(n Log n), where ‘n’ is the number of elements.

  • It works with any size of the array, be it small or large.

  • It uses additional storage, since it needs to sort the auxiliary array.

  • It uses three arrays, where two of them store two halves of the array and the third array stores the final sorted list.

  • It works well at a good speed on any data size.

  • It is considered to be efficient.

  • It is considered to be a stable sorting algorithm.

raja
Published on 23-Mar-2021 07:40:04
Advertisements