Substitution
Tags | CS161Complexity |
---|
Substitution method
This one relies on a good guess but it will show that it is a good guess
- guess the correct runtime
- prove it through induction, and get any parameters like you need
- re-do the inductive proof with these parameters
To be more specific, we hypothesize that , and then we plug this into the recurrence relationship. For example, if we wanted to show that is , we would plug in
and you would get something like
and this has a constant upper bound.
Guessing correctly
The major mode of guessing is rolling out the recurrence relationship, like what is shown below
![](Substitution%206fc5492457a94e08974d2fb24255ebc3/Untitled.png)
There’s a pretty straightforward strategy
- expand (unfold the recurrence like an onion)
- simplify (group like terms)
- notice the pattern. The best way is to look at things in terms of depth , and then you know what is (typically a logarithm). Watch out for edge cases. To check, plug in the starting depth to the formula to see if you get the original recurrence relationshp
Alternatively, you can also guess by graphing, etc.
Proving
This is a simple case of induction and it’s very similar to how you show normal complexity. You want to show that when . The best way to attempt this is through strong induction. Write out the recurrence relation, and then for each recurrent term, plug in your inductive hypothesis (namely that .
At this point, you will have an equation in terms of and . Try solving for , or a bound of it.
If you made an incorrect assumption, you will get some bound like , which is a contradiction. If you have made a correct complexity assumption, then you will get some bound of that is valid.
If you’re made it this far, you are to plug this back into the original equation and show again by induction that the assumptions are satisfied for some value of .
Things to watch out for
It can happen that the substitution method fails a complexity estimate when it is asymptotically correct.
You also can’t do induction on general , because that would mean assigning some to every value of , which is not correct. Instead, you should pick the largest term and work with lower bounds where is simple