Can I write this code using recursion better way?efficient?
Yes. Draw out how the algorithm actually works. Start from a given value, lets say 5. There is a better way to do it than like this, but here's a start:
5 recursively computes f(4), f(3), f(2).
->4 recursively computes f(3), f(2), f(1).
->3 recursively computes f(2), f(1), f(0).
So here's the BIG hint: notice how values are calculated more than once a) think about how this would be impacted with larger starting values. Is there really a need to recalculate what you've already calculated? b) if you understand the above, do you have ideas for reducing redundancy?
Edit: And suggested reading:
http://en.wikipedia.org/wiki/Memoization