Skip to content

Commit 6b27c2f

Browse files
authored
Complexity quick_sort.cpp
Space Complexity Time complexity
1 parent 136e6c0 commit 6b27c2f

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

0 commit comments

Comments
 (0)