Mergesort and Quicksort - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Mergesort and Quicksort

Description:

n = original instance size. n/b = size of subinstances. k = polynomial ... So induct on the problem size n and construct. a bound on c as we go. Basis case ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 12
Provided by: mike437
Category:

less

Transcript and Presenter's Notes

Title: Mergesort and Quicksort


1
Mergesort and Quicksort
  • Lecture 08
  • CS 312

2
Complexity Analysis of DC
l number of subinstances n original instance
size n/b size of subinstances k polynomial
order of g(n) O(nk) where g(n) cost
of doing the divide and recombination
3
Complexity Analysis of DC
Can only be applied when t(n) l t(n/b) g(n)
and g(n) in ? (nk).
4
Complexity of Mergesort
  • t(n) 2t(n/2) g(n)
  • so Equation 7.1 applies
  • l 2, b 2, k 1

5
Complexity of Quicksort
probability that Tn will be chosen as the pivot
consider the cost of each possible pivot selection
6
Complexity of Quicksort
cost of sorting each subarray
3 1 4 1 5 9 2 6 5 3 5 8 9 2 1 3 1 3 9 5 6 5 4 5
8 9
pivot around 3...
l 5
l-14
n-l8
7
Complexity of Quicksort
8
Complexity of Quicksort
Equation 7.1 does not apply. What to do? Guess
that t(n) is in O(n log n), which means that
t(n) lt c n log n for some constant c. Or, ?
c. ?n. t(n) lt c n log n
9
Constructive Induction
? c. ?n. t(n) lt c n log n Proof idea This
constant c exists, but we dont know a value.
So induct on the problem size n and construct a
bound on c as we go.
10
Basis case
  • Easy, just pick c so that
  • for any value of n between 2 and the threshold
    n0.

t(n) lt c n log n or c gt t(n)/n log n
11
Inductive step
Write a Comment
User Comments (0)
About PowerShow.com