BY: Sharra Mae S. Tagaro IV- Rizal
This week, we had a brief discussion of recursion:
*RECURSION- defined as the repetitive process by which a function calls itself. It is also termed as the CIRCULAR DEFINITION. Recursion is also a programming technique where a routine performs its task by delegating part of it to another instance of itself.
For example in this program segment:
Factorial (int n)
{
If (n==1||n==0) return 1;
else return (n * factorial (n-1));
}
In this program segment, it illustrates a function containing a call to it. The lines else return (n * factorial (n-1)); contains the function call for the factorial function.
The parts of the recursive function include the Base Case. The base case can be found in the “if clause”. It contains the condition that should be satisfied at one point of execution to terminate the repetitive process done be the recursive function. And the other part of the recursive function is the General Case. The general case can be located on the “else-clause”. It contains the function call of the recursive function to itself.
The Direct Recursion is a recursive functions that can call itself through a function call directly inside the body of the function. While the second type of recursion is the indirect recursion. The Indirect Recursion is a recursive functions that can call another function outside its function.
And we had an activity in programming about it...that's all!^-^,.
No comments:
Post a Comment