Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

QUICK SORT

L E T S P L AY
QUICK SORT
Quicksort is a fast sorting algorithm that takes a
divide-and-conquer approach to sorting lists.

Best Case Average Case Worst Case


O(N * logN) O(N * logN) O(N^2)

Quicksort has a very slow worst-case running time, but a fast


average and best-case running time.
PSEUDOC ODE
• If the list is empty, return the list and terminate. (Base case)
• Choose a pivot element in the list.
• Take all of the elements that are less than or equal to the pivot and
use quicksort on them.
• Take all of the elements that are greater than the pivot and use
quicksort on them.
• Return the concatenation of the quicksorted list of elements that are
less than or equal to the pivot, the pivot, and the quicksorted list of
elements that are greater than the pivot.
C HOOS ING A
P IVOT
• Select a random pivot.
• Select the leftmost or rightmost element as the
pivot.
• Take the first, middle, and last value of the array,
and choose the median of those three numbers as
the pivot (median-of-three method).
SI MPLE
I M PLEM E NTATION
IN
PYTHON
I M PLEM E NTATION
IN
PYTHON
THANKYOU
WE HOPE YOUR LIFE SORTS BETTER:>

You might also like