Concept explainers
What type of recursive function do you think would be more difficult to debug; one that uses direct recursion or one that uses indirect recursion? Why?
Recursive Function:
- The function has ability to call itself is called recursion function.
- It is a substitute method for reiteration.
- It replaces the loop statements, so without loop statement it executes the algorithm codes a number of times.
- Selection statement is used to make a decision for the execution of the recursion.
- There are two types of recursive functions. They are:
- Direct recursion
- Indirect recursion
Direct recursion:
When a function calls itself repeatedly until the condition becomes false is called as direct recursion.
Example:
//method definition
void test()
{
//call a function
test();
}
Indirect recursion:
When a function calls another function which in turn calls the same calling function is called as indirect recursion.
Example:
//method definition
void test()
{
//call a function
test1();
}
//method definition
void test1()
{
//call a function
test();
}
Explanation of Solution
Recursion that is difficult to debug:
The recursion that is difficult to debug is “Indirect recursion”.
Justification:
- Because, a function calls one function which is linked to another function.
- Since, a function can make multiple calls to a function; it is difficult to track the flow control of function that is being processed within the code.
Therefore, “Indirect recursion” is difficult to debug when compared to direct recursion.
Want to see more full solutions like this?
Chapter 14 Solutions
Starting Out With C++: Early Objects, Student Value Edition & Myprogramminglab With Pearson Etext -- Standalone Access Card Package, 9/e
Additional Engineering Textbook Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Software Engineering (10th Edition)
Starting Out with Python (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- How is it controlled that a recursion function be called several times? What kind of command and control structure is employed in this case?arrow_forwardWrite a recursive function that takes a positive integer and returns the factorial of that integer. Attention, the function must be recursive, and its name must be "fatorial".arrow_forwarddescribe a recursive function that cannot be rewritten as non recursivearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage