COMPUTER SCIENCE AND ENGINEERING
SOFTWARE ENGINEERING
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Consumes less memory
|
|
Less code and easy to implement
|
|
Consumes more memory
|
|
More code has to be written
|
Detailed explanation-1: -1. What is the advantage of recursive approach than an iterative approach? Explanation: A recursive approach is easier to understand and contains fewer lines of code.
Detailed explanation-2: -Approach: In recursive approach, the function calls itself until the condition is met, whereas, in iterative approach, a function repeats until the condition fails. Programming Construct Usage: Recursive algorithm uses a branching structure, while iterative algorithm uses a looping construct.
Detailed explanation-3: -Recursion uses more memory compared to iteration. In recursion, the function will call itself until the base condition is not true. So, Recursion is similar to a loop and it will call itself until the base condition is not true. Iteration requires less memory than recursion.
Detailed explanation-4: -7. What is the advantage of iterative code for finding power of number over recursive code? Explanation: Both iterative and recursive approach can be implemented in log n time but the recursive code requires memory in call stack which makes it less preferable. 8.
Detailed explanation-5: -The major difference between the iterative and recursive version of Binary Search is that the recursive version has a space complexity of O(log N) while the iterative version has a space complexity of O(1). Hence, even though recursive version may be easy to implement, the iterative version is efficient.