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 (10th Edition)
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_forwardFor any part that requires recursion, if you do not create a recursive function, that will result in a on that part.arrow_forwardHow much more time and space in memory does running recursive functions take?arrow_forward
- Which of the basic data structures is the most suitable if you only need to implement recursion in a programming language? When you make a recursive call, you need to save the function you are currently in and its parameters values in some data structure, so that when you go out of the recursion you can restore the state. When you go out of the recursive call, you will always need to extract the last element that was put in the data structure. A. Queue B. Stackarrow_forwardRecursion in programming is described as when a function/method makes a direct or indirect call to itself. Which of the features is not valid for a recursive function. Select one: a. The Recursive calls can be more then one b. The Recursive Call – the function calls itself with an input which is a step closer to the stop condition c. The Stoping Conditions can be more than one d. The Recursive call is optional. e. A Stop Condition – the function returns a value when a certain condition is satisfied, without a further recursive callarrow_forwardIn C++ 1 - Print a pyramid using recursive functions like this. 2 - Make it space properly for up to 20arrow_forward
- Why is it required to provide a base case for every recursive function?arrow_forwardTrue or False Recursion can be done by calling a function once C programming languagearrow_forwardWhy, when using recursion to solve a problem, does the recursive function have to call itself in order to solve a smaller version of the original problem?arrow_forward
- Implement a recursive C++ function which takes two integers num and den as arguments and returns theinteger quotient that will result when num is divided by den. The prototype of your function should be:int quotient (int num, int den)Hint: Think about repeated subtractionarrow_forwarddescribe a recursive function that cannot be rewritten as non recursivearrow_forwardPerform in C#arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning