Question
What is the primary difference between recursion and
iteration in programming?Solution
Recursion involves a function calling itself until a base condition is met. Each recursive call creates a new stack frame, leading to memory usage that grows with the depth of recursion. Iteration, on the other hand, uses loops and does not involve stack frame creation, making it more memory-efficient in many cases. Why Other Options Are Incorrect: 1. Recursion uses loops for repetition, whereas iteration does not: This statement reverses the roles. Recursion relies on function calls for repetition, while iteration explicitly uses loops (for, while). 2. Iteration cannot solve problems that recursion can solve: Iteration can replicate recursion's functionality by using stacks or queues explicitly. Recursion is often a stylistic or practical choice, not a limitation of iteration. 3. Recursion is always faster than iteration: Recursion can sometimes be slower due to stack overhead and repeated function calls. Tail-call optimization can mitigate this in some languages, but generally, iteration is faster for equivalent tasks. 4. Recursion does not require a base case, while iteration requires a condition: Recursion must have a base case to terminate; otherwise, it leads to infinite calls. Iteration, too, requires a stopping condition, such as a loop exit condition.
With reference to the World Environment Day, consider the following statements:
1. It was designated by the International Union for Conservatio...
Which Indian state has launched the first-of-its-kind village-level survey for documentation and geo-tagging of antiquities?
Questions relating to the application or interpretation of a standing order certified under the Industrial Employment (Standing Orders) Act, 1946 may b...
Who is the author of the work, The Evolution of Provincial Finance in British India : A Study in the Provincial Decentralization of imperial Financer?
What is the minimum number of states required in a Turing Machine to recognize the language L = { aⁿbⁿ | n ≥ 1 }?
During the World War II, Indian soldiers fought heroically in the Batle at Monte Cassino. Where is Monte Cassino located?
Which of the following facts are not true in regards to G20?
- It was formed in 1998
- Formed in the backdrop of ...
Who among the following were conferred with Rajiv Gandhi Khel Ratna Award for the year 2016?
1. Jitu Rai
2. Dipa Karmakar
3. P....
The ______ DOES NOT function as an excretory organ in humans.
Which one of the following chromosomes has a mismatched pair in a normal human male?