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)
- For any part that requires recursion, if you do not create a recursive function, that will result in a on that part.arrow_forwardHow is it controlled that a recursion function be called several times? What kind of command and control structure is employed in this case?arrow_forwardWhich 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_forward
- How much more time and space in memory does running recursive functions take?arrow_forwardRecursive Exponentiation (using c language) Write a recursive function power(base, exponent) that when invoked returns baseexponent. For example, power(3, 4) = 3 * 3 * 3 * 3. Assume that exponent is an integer greater than or equal to 1. Then, write a demo program that uses the power function and test it out for a number of inputs. Hint: The recursion step would use the relationship baseexponent = base * baseexponent–1 and the terminating condition occurs when exponent is equal to 1 because base1 = basearrow_forwardis it possible to change this function from recursive to iterative one? Any help would be greatly appreciated.arrow_forward
- Recursion 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_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_forwardTrue or False Recursion can be done by calling a function once C programming languagearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning