C PROGRAMMING
MULTIPLE CHOICE QUESTION
OLD QUESTION BANK
SAMPLE QUESTION 2080 AND SOLUTION
  • Iteration:
    • Iteration involves repeating a set of instructions in a sequence a specified number of times or until a certain condition is met.
    • It is typically implemented using loops such as for, while, or do-while.
    • Iterative solutions are often more straightforward to understand and debug, especially for programmers who are new to coding.
    • They usually have better performance in terms of memory usage and execution time compared to recursive solutions, especially for problems with large inputs.
    • Iteration is well-suited for problems that can be easily expressed using loops or where maintaining state across iterations is straightforward.
  • Recursion:
    • Recursion involves breaking down a problem into smaller, similar subproblems and solving each subproblem recursively until a base case is reached.
    • It is implemented by calling the function itself within its definition.
    • Recursion is often more elegant and concise for certain types of problems, particularly those that naturally exhibit a hierarchical structure or can be easily broken down into smaller instances of the same problem.
    • Recursive solutions may be more intuitive for certain algorithms, such as tree traversal or problems involving backtracking.
    • However, recursion can lead to stack overflow errors if not implemented carefully, as each recursive call consumes memory on the call stack. This makes it less efficient for problems with deep recursion or large input sizes.