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.
26th November is celebrated as which of the following day in India?
Doctrine of Frustration of contract is laid down under which section of the Contract Act?
Consequential damage over breach of contract was determined by the English Court in the well-known case of ________________
In which case it was held that Specific Relief Act is not an Exhaustive Law?
What is the tenure of the chairperson and members of the Competition Act, 2002?
Section 38(3)(b) of the Banking Regulation Act, 1949 lists circumstances in which the Reserve Bank may make an application for the winding up of a banki...
Which of the following is correctly matched according to Indian Evidence Act, 1872?
Right to information is a :
Section 36AD of the Banking Regulation Act, 1949 prescribes punishment for certain activities in relation to banking companies, such as obstructing pers...
Section 35B(1)(b) of the Banking Regulation Act, 1949 requires the previous approval of the Reserve Bank for certain appointments. Which of the followin...