a). Iteration and recursion are two very fundamental concepts underlying things we do in computing.
(i). In your own words, compare and contrast the terms Iteration and Recursion in the context of solving problems in business, science or engineering; and explain the areas of use (in practice) of each of them.
(ii). Using practical examples in business, science or engineering, explain reasons why people still use recursion to solve problems even-though iteration is more efficient.
(b). In various fields of human endeavor, we use queues and stacks on daily basis.
(i). In your own words, distinguish between queues and stacks in the context of computer-based information systems as against business operations; and draw a table of comparison to illustrate your answer.
(ii). Provide two practical examples where we use queues and/or stacks in each of the following fields:
(i). Business
(ii). Education
(iii). Manufacturing
(iv). Computer Science
Answers
Answer:
b 5 points me itna bara answer nahi de raha
Answer:
Time Complexity: Finding the Time complexity of Recursion is more difficult than that of Iteration.
Recursion: Time complexity of recursion can be found by finding the value of the nth recursive call in terms of the previous calls. Thus, finding the destination case in terms of the base case, and solving in terms of the base case gives us an idea of the time complexity of recursive equations. Please see Solving Recurrences for more details.
Iteration: Time complexity of iteration can be found by finding the number of cycles being repeated inside the loop.
Usage: Usage of either of these techniques is a trade-off between time complexity and size of code. If time complexity is the point of focus, and number of recursive calls would be large, it is better to use iteration. However, if time complexity is not an issue and shortness of code is, recursion would be the way to go.
Recursion: Recursion involves calling the same function again, and hence, has a very small length of code. However, as we saw in the analysis, the time complexity of recursion can get to be exponential when there are a considerable number of recursive calls. Hence, usage of recursion is advantageous in shorter code, but higher time complexity.
Iteration: Iteration is repetition of a block of code. This involves a larger size of code, but the time complexity is generally lesser than it is for recursion.
Overhead: Recursion has a large amount of Overhead as compared to Iteration.
Recursion: Recursion has the overhead of repeated function calls, that is due to repetitive calling of the same function, the time complexity of the code increases manifold.
Iteration: Iteration does not involve any such overhead.
Infinite Repetition: Infinite Repetition in recursion can lead to CPU crash but in iteration, it will stop when memory is exhausted.
Recursion: In Recursion, Infinite recursive calls may occur due to some mistake in specifying the base condition, which on never becoming false, keeps calling the function, which may lead to system CPU crash.
Iteration: Infinite iteration due to mistake in iterator assignment or increment, or in the terminating condition, will lead to infinite loops, which may or may not lead to system errors, but will surely stop program execution any further.
Property Recursion Iteration
Definition Function calls itself. A set of instructions repeatedly executed.
Application For functions. For loops.
Termination Through base case, where there will be no function call. When the termination condition for the iterator ceases to be satisfied.
Usage Used when code size needs to be small, and time complexity is not an issue. Used when time complexity needs to be balanced against an expanded code size.
Code Size Smaller code size Larger Code Size.
Time Complexity Very high(generally exponential) time complexity. Relatively lower time complexity(generally polynomial-logarithmic).