I'm trying to prove that the following recurrence relation has a runtime of O(n)
:
fac(0) = 1
fac(n+1) = (n + 1) * fac(n)
I think that I can use induction in the following manner:
Base case
If n=0
then fac(n) = fac(0) = 1
Inductive case
Assume that fac(n)
has a runtime of O(n)
fac(n+1) = (n + 1) * fac(n)
Therefore fac(n+1)
has a runtime of O(n+1)
However, I have a suspicion that my inductive case doesn't really prove much. Maybe this is because the my assumption for the inductive case is wrong?
Can you point me in the right direction to prove this runtime?
fac(n)
(which is $n!$)? – David Richerby May 25 '14 at 15:12