Implement the Quick Sort algorithm, which is a Divide and Conquer technique, to sort an array arr[] in ascending order. Given an array arr[], with a starting index low and an ending index high, complete the functions partition() and quickSort(). The pivot should be chosen as the last element of the array, such that all elements smaller than or equal to the pivot are placed before it, and all elements greater than the pivot are placed after it.
Note: The indices low and high are inclusive.
Example 1
Input: arr[] = [4, 1, 3, 9, 7]
Output: [1, 3, 4, 7, 9]
Explanation: After sorting, all elements are arranged in ascending order.
Example 2
Input: arr[] = [2, 1, 6, 10, 4, 1, 3, 9, 7]
Output: [1, 1, 2, 3, 4, 6, 7, 9, 10]
Explanation: Duplicate elements (1) are retained in sorted order.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
4 1 3 9 7
1 3 4 7 9
2 1 6 10 4 1 3 9 7
1 1 2 3 4 6 7 9 10