Lecture 8
Lecture 8
Lecture 8
Quicksort
Partition is balanced
Works out to
T(n) = (n2)
1 n 1
T n T k T n 1 k n
n k 0
What is each term under the summation for?
What is the (n) term for?
So
1 n 1
T n T k T n 1 k n
n k 0
2 n 1
T k n
n k 0
Write it on
the board
T(n) = O(n lg n)
T(n) = O(n lg n)
Whats the inductive hypothesis?
T(n) = O(n lg n)
T(n) an lg n + b for some constants a and b
T(n) = O(n lg n)
What value?
T(n) = O(n lg n)
T(n) = O(n lg n)
Grind through it
2 n 1
ak lg k b n
n k 0
Plug
What
in inductive
are we doing
hypothesis
here?
n 1
2
b ak lg k b n
n
k 1
Expand
case
Whatout
arethe
we k=0
doing
here?
2 n 1
2b
ak lg k b
n
n k 1
n
2 n 1
ak lg k b n
n k 1
Distribute
thewe
summation
What are
doing here?
2a n 1
2b
Evaluate the summation:
k
lg
k
(
n
1
)
n
What are we doing here?
b+b++b
= b (n-1)
n k 1
n
2a n 1
k lg k 2b n
n k 1
This summation gets its own set of slides later
Since
n-1<n,
2b(n-1)/n
< 2b
What
are we
doing here?
n k 1
2a 1 2
1 2
Wellthe
prove
this later
hell?
n lg n n 2b n What
n 2
8
a
an lg n n 2b n
Distribute
thewe(2a/n)
What are
doingterm
here?
4
a
Tightly Bounding
The Key Summation
n 1
n 2 1
n 1
k 1
k 1
k n 2
n 2 1
n 1
k 1
k n 2
k lg k k lg k k lg k
k lg k k lg n
n 2 1
n 1
k 1
k n 2
k lg k lg n k
Tightly Bounding
The Key Summation
n 1
n 2 1
n 1
k 1
k 1
k n 2
k lg k k lg k lg n k
n 2 1
n 1
k 1
k n 2
k lg n 2 lg n k
n 2 1
k lg n 1 lg n
k 1
lg n 1
n 1
lg n/2
= lg
n we
- 1 doing here?
What
are
k n 2
n 2 1
n 1
k 1
k n 2
k lg n k
Tightly Bounding
The Key Summation
n 1
n 2 1
n 1
k 1
k 1
k n 2
k lg k lg n 1 k lg n k
lg n
n 2 1
n 2 1
k 1
k 1
k lg n
n 1
n 2 1
k 1
k 1
lg n k
n 1
Distribute
the
(lg nhere?
- 1)
What
are we
doing
k n 2
n 1 (n)
lg n
2
n 2 1
k
k 1
TheWhat
Guassian
are weseries
doing here?
Tightly Bounding
The Key Summation
n 1 (n)
k lg k
lg n
k 1
n 1
n 2 1
k 1
n 2 1
1
n n 1 lg n k
2
k 1
1
1 n n
n n 1 lg n 1
2
2 2 2
1 2
1 2 n
n lg n n lg n n
2
8
4
X Guassian
What are series
we doing?
Multiply it
What are we doing?
all out
Tightly Bounding
The Key Summation
n 1
1 2
1 2 n
k lg k n lg n n lg n n
2
8
4
k 1
1 2
1 2
n lg n n when n 2
2
8
Done!!!