QuickSort is a sorting algorithm that works by recursively dividing an array into smaller sub-problems using a pivot element. Choosing a good pivot is important for QuickSort's performance. If the pivot is always the first element and the array is already sorted, QuickSort runs in quadratic time. If the pivot is always the median element, QuickSort runs in linear time on average.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
45 views7 pages
Algo Qsort Pivot Annotated
QuickSort is a sorting algorithm that works by recursively dividing an array into smaller sub-problems using a pivot element. Choosing a good pivot is important for QuickSort's performance. If the pivot is always the first element and the array is already sorted, QuickSort runs in quadratic time. If the pivot is always the median element, QuickSort runs in linear time on average.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7
QuickSort
Design and Analysis of Algorithms I
Choosing a Good Pivot
QuickSort: High-Level Description
The Importance of the Pivot
Tim Roughgarden
Suppose we implement QuickSort so that
ChoosePivot always selects the first element of the array. What is the running time of this algorithm on an input array that is already sorted? Not enough information to answer question
Suppose we run QuickSort on some input, and,
magically, every recursive call chooses the median element of its subarray as its pivot. Whats the running time in this case? Not enough information to answer question