Recursion Unraveled: Understanding the Flow Quiz

  1. Identifying the Base Case

    In a recursive factorial function where factorial(0) returns 1, what is the role of this base case in the control flow?

    1. It stops further recursive calls by providing a direct answer for the simplest input.
    2. It speeds up multiplication using memoization.
    3. It converts recursion into iteration automatically.
    4. It increases the stack size to prevent overflow.
    5. It sorts the intermediate results before returning.
  2. When the Base Case Is Missing

    If a recursive function for computing the length of a list never checks for an empty list, what is the most likely outcome at runtime?

    1. A stack overflow due to infinite recursion.
    2. A queue overflow due to breadth-first calls.
    3. A compile-time error because recursion is not allowed.
    4. Silent termination with a default value.
    5. Automatic tail-call optimization fixing the issue.
  3. Order of Actions: Before and After the Call

    Given a function step(n) that prints 'down' when n u003E 0, then calls step(n-1), and finally prints 'up', what sequence is printed when n is 2?

    1. down, down, up, up
    2. down, up, down, up
    3. up, up, down, down
    4. down, down, down, up
    5. up, down, up, down
  4. Stack Space in Linear Recursion

    For a linear recursive function that decreases n by 1 until it reaches 0, what is the additional space complexity due to the call stack as a function of n?

    1. O(n)
    2. O(1)
    3. O(log n)
    4. O(n^2)
    5. O(nn)
  5. Understanding Tail Recursion

    Which statement best describes tail recursion in terms of control flow?

    1. The recursive call is the final action in the function, so no work remains after it returns.
    2. The recursive call happens at the start and is called a tale call.
    3. Tail recursion always runs faster than loops regardless of the language.
    4. Tail recursion increases the depth of the call stack on purpose.
    5. Tail recursion means the function calls two tails of the input at once.