QuickSort in Java

Quicksort or partition-exchange sort, is a fast sorting algorithm, which is using divide and conquer algorithm. Quicksort first divides a large list into two smaller sub-lists: the low elements and the high elements. Quicksort can then recursively sort the sub-lists.

Steps to implement Quick sort:

1) Choose an element, called pivot, from the list. Generally pivot can be the middle index element.
2) Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
3) Recursively apply the above steps to the sub-list of elements with smaller values and separately the sub-list of elements with greater values.

Quick Sort


The complexity of quick sort in the average case is Θ(n log(n)) and in the worst case is Θ(n2).



Sorted elements are :
The array is 0
The array is 1
The array is 3
The array is 4
The array is 5
The array is 7
The array is 9
The array is 11

Insertion Sort


Bubble Sort