What is sorting ?
Sorting is the process of arranging numbers in ascending or descending order. Sorting can be done on numbers, names or records, and every sorting is done in some manner.
In this method, there is a pivot element. The position of the pivot element is fixed, and numbers less than it is placed at its left and the greater one placed at its right. They make two arrays in a quick sort array; one holds the smaller elements than the pivot, and another holds a greater one. The average time complexity of this method is o(n2). This method is useful for a large number of datasets.
- Choose the highest number as a pivot element.
- Take two variables to the left and right side of the array.
- Left points to low elements.
- Right points to high elements.
- When the value is less than pivot then move right.
- When the value is higher than pivot then move left.
- If both stem 5 and 6 don't match the swap left and right.
- If left >= right then meet a new pivot.
Advantages of Quick sort
- It requires n(log n) to sort n times.
- It has a short inner loop
- It uses a small stack for sorting.
Disadvantages of Quick sort
- It is a recursive method and takes time.
- It requires quadratic time.
- Simple mistakes can affect the performance very badly.