# Quick Sort vs. Merge Sort

## Contents: Difference between Quick Sort and Merge Sort

### Main Difference

The key difference between quick sort and merge sort is that quick sort is the sorting algorithm that is used on arrays whereas merge sort is the sorting algorithm that works on divide and conquers rule. Sorting is arranging elements in any order; sorting is one of the most important concepts in computer programming. Two most important algorithms are used for sorting purpose one is the quick sort that is quick sort is the sorting algorithm that is used on arrays, and other is merge sort that is sorting algorithm that works on divide and conquers rule. Working of both algorithms is the same, but they are different as their code is different. In quick sort, pivot element is used for the sorting whereas in merge sort pivot element perform sorting.

Quick sort algorithm is best for quick sorting of short arrays; elements are array are divided until no more division can occur. Another name for quick sort is partition exchange sort.  There is a key element that is responsible for the positioning the elements for sorting in an array. The key element is known as a pivot. In the quick sort algorithm, the first element of an array is selected, and that selected element is made a key. Two pointers are a low pointer and up a pointer that is low = 2 and up =n. Low pointer is incremented as ([low] > key). On the other hand, up pointer is decremented as ([up] <key). Up pointer cannot be greater than low pointer if up pointer is high than a low pointer, they are interchanged. The process of interchanged is kept on going until up <= low. The left element of the array cannot be greater than the key, and the right element of the array should be greater than the key. After this whole algorithm work, an array is sorted.

Merge sort is sorting algorithm that works on divide and conquers rule. The array is divided into two parts and again divided until more division cannot happen. Merge sort decrease the sorting time. Three arrays are used in merge sort, one array to sort one half of array, the second array to store other half and final array to store final and sorted list. The code of merge sort will explain the working and difference of merge sort and quick sort.

### Comparison Chart

 Basis Quick sort Merge sort Meaning Quick sort is the sorting algorithm that is used on arrays. Merge sort is the sorting algorithm that works on divide and conquers rule. Complexity The time complexity of quick sort is 0 (n^2) Time complexity of merge sort is 0 (n log n) Efficiency Quit sort algorithm is less efficient than merge sort. Merge sort algorithm is more efficient than quick sort. Sorting method Sorting method of quick sort is internal. Sorting method of merge sort is external.

### Quick sort

Quick sort algorithm is best for quick sorting of short arrays; elements are array are divided until no more division can occur. Another name for quick sort is partition exchange sort.  There is a key element that is responsible for the positioning the elements for sorting in an array.

The key element is known as a pivot. In the quick sort algorithm, the first element of an array is selected, and that selected element is made a key. There are two pointers that are a low pointer and up a pointer that is low = 2 and up =n. Low pointer is incremented as ([low] > key). On the other hand, up pointer is decremented as ([up] <key). Up pointer cannot be greater than low pointer if up pointer is high than a low pointer, they are interchanged. The process of interchanged is kept on going until up <= low. The left element of the array cannot be greater than the key, and the right element of the array should be greater than the key. After this whole algorithm work, an array is sorted.

### Merge Sort

Merge sort is sorting algorithm that works on divide and conquers rule. The array is divided into two parts and again divided until more division cannot happen. Merge sort decrease the sorting time.

Three arrays are used in merge sort, one array to sort one half of array, the second array to store other half and final array to store final and sorted list. The code of merge sort will explain the working and difference of merge sort and quick sort.

### Key Differences

1. Quick sort is the sorting algorithm that is used on arrays whereas Merge sort is the sorting algorithm that works on divide and conquers
2. The time complexity of quick sort is 0 (n^2) whereas Time complexity of merge sort is 0 (n log n).
3. Quit sort algorithm is less efficient than merge sort whereas Merge sort algorithm is more efficient than quick sort.
4. Sorting method of quick sort is internal whereas Sorting method of merge sort is external.

### Conclusion

In this article above we see the clear difference between quick sort and merge sort.