Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a recursive function, and I'm trying to figure out it's complexity. denote P(n) - the runtime of the function (when given the parameter n). I know that : P(n)=n+(n-1)*P(n-1) [p(1)=1]

How can I express P(n) without using P(...) ?

share|improve this question
    
oeis.org/… –  David Mitra Dec 30 '11 at 11:06

1 Answer 1

up vote 1 down vote accepted

You can write it something like $P(1)-1 = 0$, $P(n+1)-1 = n (2 + P(n)-1)$.

Now let's define $Q(n)=\frac{P(n)-1}{2}$ and we have $Q(1) = 0$, $Q(n+1) = n (1 + Q(n))$.

Now Q(5) is something like

5 (1 + 4 (1 + 3 (1 + 2 (1 + 1 (1 + 0)))))

5 + 5 * 4 + 5 * 4 * 3 + 5 * 4 * 3 * 2 + ...

and that's clearly less than

6!

So you could prove that P(n) is O(n!) along these lines.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.