Skip to content
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
19 changes: 9 additions & 10 deletions Algorithms/Sorting Algorithms/Quick sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def quickSort(arr, start, end):

Quick Sort can be optimized from O(N) and O(N logN) to O(logN) using tail recursion.It reduces the complexity by solving smallest partition first which improves the time complexity of Quick Sort to O(log N).
### Code `C++`
```
```cpp
void QuickSortOptimized(int arr[],int start,int end){
while(start<end){
int PartitionIndex = partition(arr,start,end); //Getting the Partition index
Expand All @@ -132,18 +132,17 @@ void QuickSortOptimized(int arr[],int start,int end){
}

int partition(int arr[], int start, int end) {
int PartitionIndex = start;
int PartitionValue = arr[end];
int PartitionIndex = start;
int PartitionValue = arr[end];

for (int i = start; i < end; i++) {
if (arr[i] <= PartitionValue) {
swap(arr, i, PartitionIndex++);
}
for (int i = start; i < end; i++) {
if (arr[i] <= PartitionValue) {
swap(arr, i, PartitionIndex++);
}
swap(arr, end, PartitionIndex);
return PartitionIndex;
}

swap(arr, end, PartitionIndex);
return PartitionIndex;
}
```

#### ⏲️ Time Complexities:
Expand Down