HW1 Submitted!
Due yesterday @ 11:59pm
Homework Tips!
HW2 Released Today @ 5pm!
Due Next Tuesday @ 11:59pm
1. Welcome to COMP 285
Lecture 6: Substitution Method & Median Selection
COMP - 285
Advanced Algorithms
Lecturer: Luis Perez (laperez@ncat.edu)
Big Topics!
From Last Lecture
The Substitution Method
A first example
A first example
A first example
Step 1: Guess the Answer!
Step 2: Prove the guess is correct
Induction!
Step 2: Prove the guess is correct
Step 3: Profit
Big Topics!
Another example (practice makes perfect!)
Step 1: Make a guess - maybe from diving inspiration!
Step 2: Prove it, working backwards to get the constant C
Inductive Step
Step 2: Prove it, working backwards to get the constant C
Step 3: Profit
Isn’t Master Theorem enough?
No!
Let’s Review What We’ve Learned So Far…
The Master Theorem
number of subproblems
Factor by which input size shrinks
word needed to combine the solutions
The Substitution Method
A fun recurrence relation…
Step 1: Guess the Answer!
Step 2: Proof your guess is right!
≤𝑘+𝑪⋅(𝑘/5)+𝑪⋅(7𝑘/10)
=𝑘+𝑪/5 𝑘+7𝑪/10 𝑘
≤𝑪𝑘 ??
(aka, want to show that IH holds for n=k).
Conclusion: There is some 𝑪 so that for all 𝑛≥1, 𝑇(𝑛)≤𝑪𝑛. By the definition of big-Oh, T(n) = O(n).
Step 2: Proof your guess is right!
≤𝑘+𝑪⋅(𝑘/5)+𝑪⋅(7𝑘/10)
=𝑘+𝑪/5 𝑘+7𝑪/10 𝑘
≤𝑪𝑘 ??
(aka, want to show that IH holds for n=k).
Conclusion: There is some 𝑪 so that for all 𝑛≥1, 𝑇(𝑛)≤𝑪𝑛. By the definition of big-Oh, T(n) = O(n).
Step 3: Profit
≤𝑘+10⋅(𝑘/5)+10⋅(7𝑘/10)
=𝑘+10/5 𝑘+7(10)/10 𝑘
≤10𝑘
Conclusion: For all 𝑛 ≥ 1, 𝑇(𝑛)≤10𝑛. By the definition of big-Oh, T(n) = O(n).
What did we learn?
Is this even useful!?
Yes! Many problems have recursive solutions where problem sizes are not just “take half”
The k-Select Problem
How would you solve?
Can we do better?
Let’s code it!
Goal: An O(n)-time algorithm
Can we keep going?
Can we keep going?
Next time!
How was the pace today?
41