Precise Analysis of Quicksort - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Precise Analysis of Quicksort

Description:

LeongHW, SoC, NUS (UTT2201: Introduction) Page 1. Precise ... Partition array A[1..n] using pivot x; (this takes (n 1) comparisons) Recursively A[1..k-1] ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 16
Provided by: CDTL
Category:

less

Transcript and Presenter's Notes

Title: Precise Analysis of Quicksort


1
Precise Analysis of Quicksort
  • Precise Analysis of Quicksort
  • What are lessons learnt?
  • Where can it be used?

2
Quicksort Algorithm
  • Given unsorted array

1
n
x
1
n
x
x
³ x
1
k
n
3
Quicksort Algorithm
  • Quicksort for n elements
  • Partition array A1..n using pivot x (this
    takes (n1) comparisons)
  • Recursively A1..k-1
  • Recursively Ak1..n

4
Analysis 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
5
Analysis of Quicksort
Then, we have the following recurrence
?Expand the summations
6
Analysis of Quicksort
Then, we have the following recurrence
?Get rid of dependence on full history
7
Analysis of Quicksort
Then, we have the following recurrence
?Divide by n(n1)
8
Analysis of Quicksort
Then, we have the following recurrence
? Now telescope
9
Analysis of Quicksort
Then, we have the following recurrence
? Now telescope
10
Analysis of Quicksort
Then, we have the following recurrence
11
Analysis of Quicksort
Then, we have the following recurrence
12
Analysis of Quicksort
Average running time of Quicksort
13
Not that difficult, right?
  • Where are the key steps?
  • Get rid of full history
  • Telescope
  • Are there other ways?
  • Simpler, but not so accurate?

14
Review of the Key Steps
From here, show that
Further, show that
It follows immediately, that
15
Where can it be used?
  • Average height of a binary search tree
  • 1.386 lg n
Write a Comment
User Comments (0)
About PowerShow.com