Quick Sort divides the array(or given data structure) into two partition recursively and does in place sorting while forming partition. It doesn't require any extra storage as it does in place sorting.
For every partition, a pivot is selected such that this pivot in bought to a point(somewhere in the middle) such that the elements on the left side of this pivot are lesser than it and the elements on the right side of the pivot are greater than it.
This algorithm falls under Divide & Conquer Technique which is divides the problem, finds the solution to smaller problem and then merges these to get the solution to the original problem. Let's look at the working of this algorithm.
Do refer the code available the end of this section to understand the following theory.
PS: We give random inputs because the no. of input will generally be 100 or 1000 to find the time complexity and manually giving so many inputs is cumbersome work.
There exists two recursive calls in which the elements gets partitioned in each call. The basic operation in this algorithm is the comparison between at step 3.3 in the above working procedure. So increment the count variable above this if condition to get the count of no. of times the basic operation has been performed.
Time Complexity: θ(nlog(n))
Please open this in your pc or with a compatible app in your mobile.
C++ Implementation for QUICK SORTThat's it from this blog post. If you liked it then do share this blog with your friends or people who wanna get into programming world. Thank You!