Array ( [0] => [1] => questions [2] => Popular-Algorithms [3] => Quick-Sort )
Given a list of integers and a integer (size of array). Sort the given array using Quick Sort Algorithm.
First line contains the size of array (n) followed by n integers separated by spaces.
Print the sorted array separated by spaces.
5 5 4 3 2 1
1 2 3 4 5
6 96 54 100 32 45 64
32 45 54 64 96 100
7 69 95 34 67 45 62 44
34 44 45 62 67 69 95
Login to see Discussion
Step-i) Choose the highest index value has pivot
Step-ii) Take two variables to point left and right of the list excluding pivot, left points to the low index, right points to the high.
Step-iii) While value at left is less than pivot move right, while value at right is greater than pivot move left.
Step-iv) If both step 5 and step 6 does not match swap left and right.
Step-v) If left ≥ right, the point where they met is new pivot.
Time Complexity: O(n log n)
Space Complexity: O(log n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution