mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-12 06:56:59 +08:00
docs: add time and space complexity to quick_sort.cpp (#2819)
* Complexity quick_sort.cpp Space Complexity Time complexity * Update sorting/quick_sort.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> * Update sorting/quick_sort.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --------- Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com>
This commit is contained in:
@@ -54,7 +54,18 @@ namespace quick_sort {
|
||||
* @param low first point of the array (starting index)
|
||||
* @param high last point of the array (ending index)
|
||||
* @returns index of the smaller element
|
||||
*/
|
||||
*
|
||||
* ### Time Complexity
|
||||
* best case, average Case: O(nlog(n))
|
||||
* Worst Case: O(n^2) (Worst case occur when the partition
|
||||
* is consistently unbalanced.)
|
||||
|
||||
* ### Space Complexity
|
||||
* average Case: O(log(n))
|
||||
* Worst Case: O(n)
|
||||
* It's space complexity is due to the recursive function calls and partitioning process.
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
int partition(std::vector<T> *arr, const int &low, const int &high) {
|
||||
T pivot = (*arr)[high]; // taking the last element as pivot
|
||||
|
||||
Reference in New Issue
Block a user