Quick Sort Algorithm Details
Quick Sort Algorithm Details
1. Introduction:
Quick Sort is a widely used and efficient sorting algorithm developed by Tony Hoare in 1959. It
employs a divide-and-conquer strategy to sort elements. The main concept involves selecting a
'pivot' element and partitioning the array into two sub-arrays according to whether they are less than
2. Problem Statement:
Given an array of n elements, sort the elements in ascending order using the Quick Sort algorithm.
3. Technique:
Quick Sort works by selecting a pivot element from the array. The partition process rearranges the
elements so that all elements less than the pivot are on the left and all greater are on the right. This
4. Steps:
5. Algorithm:
pivot = arr[high]
i = low - 1
i=i+1
return i + 1
6. Implementation in C:
#include <stdio.h>
int t = *a;
*a = *b;
*b = t;
i++;
swap(&arr[i], &arr[j]);
return (i + 1);
quickSort(arr, pi + 1, high);
printf("\n");
int main() {
int n = sizeof(arr)/sizeof(arr[0]);
quickSort(arr, 0, n - 1);
printf("Sorted array: \n");
printArray(arr, n);
return 0;
7. Implementation in Python:
pivot = arr[high]
i = low - 1
i += 1
return i + 1
quick_sort(arr, low, pi - 1)
quick_sort(arr, pi + 1, high)
arr = [10, 7, 8, 9, 1, 5]
quick_sort(arr, 0, len(arr) - 1)
i++;
arr[i] = arr[j];
arr[j] = temp;
arr[i + 1] = arr[high];
arr[high] = temp;
return i + 1;
sort(arr, pi + 1, high);
}
}
int n = arr.length;
ob.sort(arr, 0, n - 1);
System.out.println("Sorted array:");
9. Expected Output:
Sorted array: 1 5 7 8 9 10
10. Advantages:
11. Disadvantages:
13. Conclusion:
Quick Sort is one of the most efficient and commonly used sorting algorithms due to its
average-case efficiency and simplicity. Although it suffers from worst-case performance in specific
scenarios, it remains popular due to its in-place nature and ease of implementation. With proper
pivot selection (e.g., using median-of-three or random pivot), its performance can be significantly