Skip to content

Commit da53b26

Browse files
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 <[email protected]> * Update sorting/quick_sort.cpp Co-authored-by: realstealthninja <[email protected]> --------- Co-authored-by: realstealthninja <[email protected]>
1 parent 3f6876f commit da53b26

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

sorting/quick_sort.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ namespace quick_sort {
5454
* @param low first point of the array (starting index)
5555
* @param high last point of the array (ending index)
5656
* @returns index of the smaller element
57-
*/
57+
*
58+
* ### Time Complexity
59+
* best case, average Case: O(nlog(n))
60+
* Worst Case: O(n^2) (Worst case occur when the partition
61+
* is consistently unbalanced.)
62+
63+
* ### Space Complexity
64+
* average Case: O(log(n))
65+
* Worst Case: O(n)
66+
* It's space complexity is due to the recursive function calls and partitioning process.
67+
*/
68+
5869
template <typename T>
5970
int partition(std::vector<T> *arr, const int &low, const int &high) {
6071
T pivot = (*arr)[high]; // taking the last element as pivot

0 commit comments

Comments
 (0)