Page 39 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 39
Fundamentals of Data Structures
Notes Self Assessment
State whether the following statements are true or false:
1. Recursion is a computer programming technique involving the use of a procedure,
subroutine, function, or algorithm that calls itself in a step having a termination condition.
2. A recursive expression is a function, algorithm, or sequence of instructions that loops back
to the beginning of itself until it detects that some condition has been satisfied.
3. Recursion may lead to increase in code size.
4. As long as the efficiency is not the primary concern, or if the efficiencies of the various
solutions are comparable, then you should use the recursive solution.
5. Problems are difficult to solve through recursion.
6. Recursion may require large amounts of memory.
3.2 Recursive Function
A recursive function is a function that calls itself during its execution. This enables the function
to repeat itself several times, outputting the result and the end of each iteration. That is, a
function is called “recursive” if a statement within body of that function calls the same function.
For example, look at below code:
void main()
{
printf(“recursive function called.\n”);
main();
}
When you will run this program it will print message “recursive function called.” indefinitely.
Recursive function example output is given as below.
Source: http://rajkishor09.hubpages.com/hub/C-Programming-Recursive-Function
32 LOVELY PROFESSIONAL UNIVERSITY