Below is the solution but I have trouble understanding 1 part of the proof by induction part. Why can you just add + 2 to one side and +4 to the other?
We're dealing with the function T(n) = 2n + 2
We want to find a c such that T(n) <= c * f(n)
for large n
We have T(n) = 2n + 2
and f(n) = n
, so we need 2n + 2 <= c * n
We solve for c and get 2 + 2/n
2/n
is undefined at n = 0, so we pick t >= 1
. We'll pick t=1
, so c=4
Proof by induction:
T(n) <= c * f(n)
(2n + 2) <= (4)(n)
+2 +4 <---- Don't understand
2n + 4 <= 4n + 4
2(n + 1) + 2 <= 4(n + 1)
T(n + 1) <= c * f(n + 1)
Conclusion: 2n + 2 ∈ O(n)