Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to to, let us concentrate rather on explaining to human beings what we want a computer to do. Donald Knuth

Using a random number to choose a pivot in quicksort

Language Java | Level Intermediate | Category Algorithms | August 5, 2015 9:03 am


Algorithm Problem Description

Quicksort is an efficient comparison sorting algorithm. It can operate in place on an array, requiring small additional amounts of memory to perform sorting.

Quicksort can be faster than merge sort and heap sort. Quick sort is one of the divides and conquers strategy algorithm. It requires careful selection of pivot element. Even if the array nearly sorted or sorted the quicksort takes the same complexity. If the array nearly sorted, we can choose insertion sort for better complexity.

Write a program to implement the quicksort.

Output

          	        
          	        

Unsorted array before sorting: [12, 34, 56, 23, 45, 78, 46]
Sorted array After Quicksort sorting: [12, 23, 34, 45, 46, 56, 78]

          	        
          	        				    


Comments



Please login to add comments.