## Quick Sort

This is a technique to sort a given array in an acending order.

Here is the steps we follow while performing quick sort :-

- The last element of array is assumed to be "infinity".
- " i " (which is an integer type variable) point to the lowest index and " j " (another integer type variable) points to the highest index of the array.
- First element is assinged asthe "pivot" element.
- " i " is incremented till larger or equal element than pivot is found.
- " j " is decremented till smaller or equal element then pivot is found.
- If " i " is less than " j " then interchange a[i] with a[j] and repeat the steps 4 and 5, else interchange a[j] and "pivot".

When the element (a[j]) is exchanged with "pivot" then the position of that element is fixed in the array and divides the array into two parts ie. on the right of the array all maximum elemnts will be there and on the left of the array all minimum elements will be there. Now sort the two parts in the same manner as of the parent array.

Now as we see that the no. of iterations will be " n log_{2}(n )" since " 2^{x }" times of comparison is made in one iteration and total number of iterations is "n", hence the total number of iterations will be " n X 2^{x} " ie. " n log_{2}(n)^{} ".

Hence, the complexcity of this sorting technique is n log_{2}(n).

" n " here is the size of the array.

Now we will discuss how did the term log_{2}(n) came.

Since 2^{x }iterations are made and in the worst case the "2^{x} = n".

Then,

x = log_{2}(n)

Where " log_{2} " refers to the base of logarithmic function ie. 2.

Hope when you read this article your understanding will we enhanced and you will be able to write the coding efficiently.

Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.

## Comments (0)