What is the run time of quicksort on array that is in decreasing order:
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Each division (partition) step reduces the problem size by one element. Therefore, each recursive call divides the array into two subarrays of sizes 0 and n − 1 , and then sorting those arrays into subarrays creates arrays of size 0 and n − 2 and so on.
The recurrence for this is:
T ( n ) = T ( 0 ) + T ( n − 1 ) + O ( n ) = T ( n − 1 ) + O ( n )
The solution to this recurrence, which we can find using the Master Theorem , is O ( n 2 )