From 6b27c2f2d7a5ffa09e5ef194cc7305cb347b7fbe Mon Sep 17 00:00:00 2001 From: jiya <122276932+jiya10208@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:22:35 +0530 Subject: [PATCH 1/3] Complexity quick_sort.cpp Space Complexity Time complexity --- sorting/quick_sort.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 514361444e4..646f83f3aff 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -53,7 +53,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 int partition(std::vector *arr, const int &low, const int &high) { T pivot = (*arr)[high]; // taking the last element as pivot From 576fce6b22c773f208464108fa39234249f66191 Mon Sep 17 00:00:00 2001 From: jiya <122276932+jiya10208@users.noreply.github.com> Date: Sun, 20 Oct 2024 10:40:41 +0530 Subject: [PATCH 2/3] Update sorting/quick_sort.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --- sorting/quick_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 646f83f3aff..2c3dee740a1 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -54,7 +54,7 @@ namespace quick_sort { * @param high last point of the array (ending index) * @returns index of the smaller element * - * Time Complexity + * ### Time Complexity * best case, average Case: O(nlog(n)) * Worst Case: O(n^2) (Worst case occur when the partition * is consistently unbalanced.) From 1fa4d35566bc0c35d82da107e1867a93cd864aaf Mon Sep 17 00:00:00 2001 From: jiya <122276932+jiya10208@users.noreply.github.com> Date: Sun, 20 Oct 2024 10:40:51 +0530 Subject: [PATCH 3/3] Update sorting/quick_sort.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --- sorting/quick_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 2c3dee740a1..b8917f73d2b 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -59,7 +59,7 @@ namespace quick_sort { * Worst Case: O(n^2) (Worst case occur when the partition * is consistently unbalanced.) - * Space Complexity + * ### 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.