Cards (40)

  • Which of the following best describes the key difference between recursion and iteration?
    Recursion involves a function calling itself, iteration uses loops
  • What is the primary advantage of using recursion over iteration?
    It simplifies complex problems like tree traversal
  • In a recursive function, what is the purpose of the base case?
    To stop the recursion
  • Which of the following is a potential disadvantage of recursion?
    It can lead to stack overflow if not properly handled
  • What type of problems are particularly well-suited for recursive solutions?
    Tree traversal and backtracking problems
  • In the context of recursion vs. iteration, which statement is true regarding memory usage?
    Iteration generally uses less memory than recursion
  • What is a key characteristic of tail recursion?
    The recursive call is the last operation in the function
  • Which type of recursion is characterized by making two recursive calls in each execution?
    Binary recursion
  • What is a potential advantage of tail recursion over other forms of recursion?
    It can be optimized by compilers to use constant stack space
  • In the context of recursion, what does 'linear recursion' mean?
    The function makes a single call to itself each time it runs
  • What is a characteristic of mutual recursion?
    It involves two or more functions calling each other
  • Which of the following problems is best solved using binary recursion?
    Computing Fibonacci numbers
  • What is a potential drawback of using binary recursion for the Fibonacci sequence?
    It can lead to exponential time complexity
  • In what scenario might mutual recursion be particularly useful?
    When alternating between different aspects of a problem
  • What is a key difference between direct and indirect recursion?
    Indirect recursion involves multiple functions
  • Which statement about iteration is true?
    It generally runs faster than recursion
  • What is a potential advantage of using iteration instead of recursion?
    It uses less memory due to not creating additional stack frames
  • In C++, which of the following is NOT a type of loop?
    repeat-until loop
  • What is the primary difference between a while loop and a do-while loop?
    do-while loops always execute at least once
  • Which type of problem is generally better suited for an iterative solution rather than a recursive one?
    Simple repetitive tasks
  • ANSWER: O(2^n)
  • best describes tail recursion?
    A recursive call that occurs at the end of a function and is the last operation
  • very unsure here
  •  true about the stack usage in recursive vs. iterative implementations?
    Recursive implementations can potentially lead to stack overflow for deep recursions
  • the primary purpose of the base case in a recursive function?
    To prevent infinite recursion
  • Which of the following best describes mutual recursion?
    Two or more functions that call each other
  • OUTPUT: 1 2 3
  • Advantage of using recursion over iteration
    Simpler implementation for certain problems
  • not sure but it says the answer was O(log n)
  • True about tail call optimization?
    It can convert tail-recursive calls into iterations
  • OUTPUT: 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
  • Problems that is best suited for a recursive solution?
    Traversing a binary tree
  • ANSWER : O(n)
  •  relationship between recursion and mathematical induction?
    Recursion is a programming implementation of mathematical induction
  • What is the primary difference between direct and indirect recursion?
    Indirect recursion involves multiple functions
  • Which of the following is an example of a problem that is typically solved more efficiently with iteration than recursion?
    Calculating factorial
  • OUTPUT: 5
  • Which of the following best describes the concept of 'divide and conquer' in the context of recursive algorithms?
    Breaking a problem into smaller, similar subproblems
  • What is a potential drawback of using recursion for solving the Fibonacci sequence problem?
    It leads to a large number of redundant calculations
  • Which of the following is true about tail recursion optimization?
    It can potentially eliminate the risk of stack overflow