i would really appreciate it if u had a link to a page or a book that fully covers how recursion works ... and some
problems over it would be lovely |
"Recursion" just means a function calling itself, usually with (as here) a smaller parameter, so that (a) the problem gets "smaller" and (b) eventually "stops"!
The classic example is the factorial function: factorial(N) = N x (N-1) x (N-2) x ... x 2 x 1
which can be written as factorial(N) = N x factorial(N-1)
Eventually you will get down to factorial(1), which is just 1. So your function often has the form:
if (bottom number)
// set value for bottom number
else
// call same function with a smaller parameter
My program is of this type. It is quite common. If you want a problem to start with, I would try coding factorial(N). Another good problem is factoring into primes: once you have extracted one prime factor the other factor will be smaller than the original number, so recursion must eventually produce the whole prime factorisation - often, conveniently, in ascending order.
Recursion can also be used for mathematical problems that can be solved by iteration or proved by induction - you may be familiar with these techniques.