Title: Precise Analysis of Quicksort
1Precise Analysis of Quicksort
- Precise Analysis of Quicksort
- What are lessons learnt?
- Where can it be used?
2Quicksort Algorithm
1
n
x
1
n
x
x
³ x
1
k
n
3Quicksort Algorithm
- Quicksort for n elements
- Partition array A1..n using pivot x (this
takes (n1) comparisons)
- Recursively A1..k-1
- Recursively Ak1..n
4Analysis of Quicksort
- Let an the average time taken to sort an
array of size n using Quicksort
If pivot is at position k, then an ak-1
an-k (n1)
Prob (pivot is at position k ) 1/n
5Analysis of Quicksort
Then, we have the following recurrence
?Expand the summations
6Analysis of Quicksort
Then, we have the following recurrence
?Get rid of dependence on full history
7Analysis of Quicksort
Then, we have the following recurrence
?Divide by n(n1)
8Analysis of Quicksort
Then, we have the following recurrence
? Now telescope
9Analysis of Quicksort
Then, we have the following recurrence
? Now telescope
10Analysis of Quicksort
Then, we have the following recurrence
11Analysis of Quicksort
Then, we have the following recurrence
12Analysis of Quicksort
Average running time of Quicksort
13Not that difficult, right?
- Where are the key steps?
- Get rid of full history
- Telescope
- Are there other ways?
- Simpler, but not so accurate?
14Review of the Key Steps
From here, show that
Further, show that
It follows immediately, that
15Where can it be used?
- Average height of a binary search tree
- 1.386 lg n