Quick sort algorithm implementation in java

Quicksort algorithm implementation in java

As the name, quicksort is the most quick algorithm to sort some number. There are some other sorting algorithms like bucket sort, insertion sort, bubble sort, radix sort, etc. Among them, quicksort is very efficient. The efficacy of quicksort in worst cause is \theta(n2), in the best cause \theta(nLogn), and in the average cause, O(N log N).  
Here is the step diagram of quicksort: 

Here is the animated simulation of a quick sort algorithm. 

If we look closely, the quick sort algorithm selects the last position of the array and assumes it as a pivot. It took two variables and assign the most left and the most right value of the array. Then it compares them with the pivot and swap if the left number is smaller than then the right number. 

The algorithm steps will explain the quick sort easily: 
Step 1 − First, Choose the highest index value of array has pivot
Step 2 − Take two variables and assign the most left and the most right value of the array excluding pivot
Step 3 − left variable points to the low index of the array
Step 4 − right variable points to the high index of the array
Step 5 − if value at left variable is less than pivot, move right
Step 6 − if value at right variable is greater than pivot move left
Step 7 − if both step 5 and step 6 does not match swap left and right
Step 8 − if left ≥ right, the point where they met is new pivot.

Let's look at the Quick sort algorithm implementation in java code:



Happy Coding...

Related Post

bucket sort                                              insertion sort                                       bubble sort  

radix sort                                                 Binary search in java                         Binary search  in C

 

0/Post a Comment/Comments