Skip to content

docs: add time and space complexity to quick_sort.cpp #2819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion sorting/quick_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
int partition(std::vector<T> *arr, const int &low, const int &high) {
T pivot = (*arr)[high]; // taking the last element as pivot
Expand Down
Loading