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.
What is the increased bulk deposit limit for Regional Rural Banks (RRBs)?
What is the name of the Khelo India Winter Games 2024 mascot (a snow leopard)?
Find the correct answer:
Mother : Child :: Cloud : ?
A blanket is sold for Rs 680 at the discount of 15% and 20%. Find the printed price of the blanket?
Identify the position of stomata in plants.
In India, Micro Finance Institutions primarily target which segment of the population?
Which among the planets is orange in colour with white bands on it?
In the Indian Constitution, the provisions relating to the Finance Commission are given in this article?
‘The Palace of Illusions’, a rendition of the Hindu epic ‘Mahabharata’, was written by which of the following novelists?
Which one of the following States of India has maximum area of saline soil?