In: Computer Science
1.If one statement is nested within another statement, as in a loop or recursive call, what is the running time of the two statements when considered as a block?
the running time for the inner statement added to the running time for the outer statement |
||
the running time for the inner statement multiplied by the running time for the outer statement |
||
the running time for the inner statement divided by the running time for the outer statement |
||
the running time for the outer statement divided by the running time for the inner statement |
2. Which of the following is false regarding a recursive algorithm?
It should proceed towards a base case. |
||
Each recursive call places another activation record on the stack. |
||
It will always be more efficient than a corresponding iterative solution. |
||
Each recursive call should operate on a smaller version of the original problem |
3. What will happen if you execute a recursive algorithm that does not have a base case?
The algorithm will immediately fail. |
||
The algorithm will execute, but it will take much longer to terminate than it would if it had a base case. |
||
The algorithm will never terminate. |
||
It can not be said what will happen with only the given information |
4. What is the advantage of using dynamic programming?
Dynamic programming will work with dynamic data instead of static data (i.e., data that do not change). |
||
Dynamic programming allows a recursive algorithm to be used, but prevents the algorithm from solving the same instance of a problem more than once. |
||
Dynamic programming is an iterative, rather than a recursive technique, and thus performs more efficiently. |
||
Dynamic programming is the only way to handle multiple base cases in a recursive problem |
Answer)
1. the running time for the inner statement multiplied by the
running time for the outer statement
When the outer loop and inner loop are there the running time is the multiplication of the running time of inner and outer.
2. The below is false:
It will always be more efficient than a corresponding iterative
solution.
As iteration is always more efficient than the recursion calls.
3. If we execute a recursive algorithm that does not have a base case:
The algorithm will never terminate.
The algorithm/program will infinitely execute as it does not have a base class.
4. The advantage of using dynamic programming is:
Dynamic programming allows a recursive algorithm to be used, but prevents the algorithm from solving the same instance of a problem more than once.
Dynamic programming uses the recursion but using dynamic programming we are not calculating the same obtained results repeatedly and thus it is beneficial and faster.