+ 2
What is Recursion?
How it works?
2 Answers
+ 23
https://www.sololearn.com/discuss/307407/?ref=app
It's a function (not only) that calls itself again. ^_^
public void a() {
//.....
return a();
//.....
}
0
simply..defining something in terms of itself, eg. a function...a function can call itself to solve smaller subproblems,,,the solutions to the smaller subproblems are combined to form the solution to the problem.
there are three laws of recursion
*a base case...path through the code that doesn't call the function code again.
*a recursive case...line of code calling the function from within the function.
*the recursive case must move the problem towards the base case(so as to avoid the infinite loop)
eg..PSUEDOCODE
f(n) <*e.g. f(n) is 6*<
if n==0. <*loop*<
output 0. <*base case*<
else
output f(n-1) <*recursive case*<