Quick Sort is a divide-and-conquer algorithm that selects an element as a pivot and partitions the given array around that pivot.
There are numerous methods of selecting pivots:
In Quicksort, the best case happens when the pivot element is in the middle or close to the middle. The best-case time complexity for quicksort is O(n*logn).
This arises when the array elements are jumbled and do not appropriately climb or descend. The average case time complexity for quicksort is O(n*logn).
In quick sort, the worst case happens when the pivot element is either the largest or the smallest element. Assume that the pivot element is always the final element in the array; the worst-case scenario occurs when the array is already sorted in ascending or descending order. The worst-case time complexity for quicksort is O(n2).
The worst-case space complexity is O(n), which occurs when n recursive calls are made. A quick sort algorithm has an average space complexity of O(long).