If you have a naturally recursive problem, but must use a language which does no
ID: 3887086 • Letter: I
Question
If you have a naturally recursive problem, but must use a language which does not support recursion, why bother to examine a recursive solution? Select all that apply.
To make your boss happy.
To save space
It is probably easier to understand.
It could be coded in Java in order to learn more about problem.
A correct recursive solution could be converted to a correct iterative one.
To make your boss happy.
To save space
It is probably easier to understand.
It could be coded in Java in order to learn more about problem.
A correct recursive solution could be converted to a correct iterative one.
Explanation / Answer
Answer:
Recursion:
The function or subpart of a program which call itself during execution is called recursion. This is an efficient method in programming languages because it required the least amount of code to perform necessary functions and uses system stack to perform the function.
There are some imperative languages which do not support recursion like Fortran. Because in Fortran variable allocation is static, and not possible to implement recursion on machines because stacks are not available to all machines.
Option 1:
To make your boss happy : Does not apply
Explanation:
Depends on the type of a problem, it can say whether the problem uses recursion or not. If the problem opposes to use recursion, then for the sake of boss happiness also can’t apply for the recursion. Because it uses systems stack memory.
So, the above reason does not apply.
Option 2:
To save space : Does not apply
Explanation:
Compare to the space complexity using recursion is more than using iteration. Because recursion requires system stack for the local and formal parameters storing and instantiation of the function. So, it might lead to the stack overflow if the memory is less. That’s the reason recursion requires more space.
So, the above reason does not apply.
Option 3:
It is probably easier to understand : Does not apply
Explanation:
Recursion is not easy to understand for the end users. Because they can’t track the recursive calls easily when compared to the iteration solutions.
So, the above reason does not apply.
Option 4:
It could be coded in Java in order to learn more about problem: Apply
Explanation:
For a Natural recursive problem; If the above problem is solved in Java using recursion, then it can be understanding more about the problem. That’s the reason, it can helpful to make the solution solved easily.
So, the above reason does apply.
Option 5:
A correct recursive solution could be converted to a correct iterative one: Apply
Explanation:
In most of the cases a correct recursive solution can be converted to the correct Iterative solution. If the solution works, then the results are lean and fast. But 5 % of chance to get stack overflow errors while converting recursive to the accurate iterative solution. At that point complex recursive methods are used to overcome the stack overflow errors and memory leaks.
So, the above reason does apply.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.