# QuickSort Algorithm

#### 7/31/97

QuickSort Algorithm

How do we Partition?

QuickSort Example

Has First exceeded Last?

Has First exceeded Last?

Define the value in position First to be the Pivot

Define the value in position First to be the Pivot

Define Up to be First and Down to be Last

Define Up to be First and Down to be Last

Move Up to the first value > Pivot

Move Up to the first value > Pivot

Move Down to the first value <= Pivot

Move Down to the first value <= Pivot

Exchange these values

Exchange these values

Move Up to the first value > Pivot

Move Up to the first value > Pivot

Move Down to the first value <= Pivot

Move Down to the first value <= Pivot

Exchange them

Move Up to the first value > Pivot

Move Up to the first value > Pivot

Move Down to the first value <= Pivot

Move Down to the first value <= Pivot

Up and Down have passed each other, so exchange the pivot value and the value in Down

Up and Down have passed each other, so exchange the pivot value and the value in Down

Up and Down have passed each other, so exchange the pivot value and the value in Down

Note that all values below PivIndex are <= Pivot

and all values above PivIndex are > Pivot

This gives us two new subarrays to Partition

QuickSort Procedure Code

The Partition Algorithm is left as a program for you to figure out!

Heap Sort

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

Heap Sort

Building the Heap

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

Form the Heap Code

Author: Douglas D. Dankel II

Email: ddd@cise.ufl.edu