Free Practice Quiz Question List

2 Recursion Online Quiz Questions

Use this free practice quiz with 20 questions to review 2 Recursion, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What is the primary purpose of a base case in a recursive function?

  1. A

    It always makes two recursive calls

  2. B

    It stops further recursive calls for a known input

  3. C

    It converts recursion into iteration

  4. D

    It increases the problem size

02
Choose one
1 point

Using the recursive definition of factorial in the material, what value does factorial(4)factorial(4) return?

  1. A

    4

  2. B

    16

  3. C

    24

  4. D

    120

03
Choose one
1 point

A recursive binary search makes one call on approximately half the input and performs constant additional work. What is its running time?

  1. A

    O(1)O(1)

  2. B

    O(log⁡n)O(\log n)

  3. C

    O(n)O(n)

  4. D

    O(nlog⁡n)O(n \log n)

04
Choose all
1 point

Which steps are part of a sound process for designing a recursive solution? Select all that apply.

  1. A

    Define precisely what the subproblem should return

  2. B

    Ensure every recursive call moves closer to a base case

  3. C

    Increase the problem size at each recursive call

  4. D

    Combine the recursive result with the current computation

  5. E

    Ignore the cost of calls and call-stack depth

05
Choose all
1 point

In which situations is recursion often a clear or natural choice? Select all that apply.

  1. A

    Processing a tree structure

  2. B

    A divide-and-conquer algorithm

  3. C

    A backtracking search with branching choices

  4. D

    A simple loop whose input may be extremely large

  5. E

    A situation where stack space is severely limited

06
True or false
1 point

Recursive function calls are removed from the call stack in last-in, first-out order.

  1. A

    True

  2. B

    False

07
True or false
1 point

Python generally replaces a tail-recursive function's current stack frame instead of adding a new one.

  1. A

    True

  2. B

    False

08
Written response
1 point

For the material's correct countdown(n)countdown(n) function called as countdown(4)countdown(4), how many numbers are printed before the base case is reached?

09
Fill in the blank
1 point

The condition for which a recursive function's answer is known directly is its .

10
Fill in the blank
1 point

The maximum number of simultaneously active stack frames during a recursive computation is called .

11
Open ended
1 point

Explain how mathematical induction can establish the correctness of the recursive factorial function for every nonnegative integer.

12
Choose one
1 point

A preorder traversal recursively visits the root and then the left and right subtrees. For a binary tree with nn nodes, what is its running time?

  1. A

    O(log⁡n)O(\log n)

  2. B

    O(n2)O(n^2)

  3. C

    O(n)O(n)

  4. D

    O(2n)O(2^n)

13
Choose one
1 point

In the recursive function sum_from(a, i), which condition serves as the base case for summing the elements from index i through the end of the array?

  1. A

    i == len(a)

  2. B

    i == 0 for every input

  3. C

    a[i] == 0

  4. D

    i is increased by 2

14
Choose one
1 point

Given the recursive function countdown(n) that prints returning n after calling countdown(n - 1), what sequence is printed after calling countdown(3) reaches its base case?

  1. A

    returning 3, returning 2, returning 1

  2. B

    returning 1, returning 2, returning 3

  3. C

    returning 0, returning 1, returning 2

  4. D

    No returning messages are printed

15
Choose one
1 point

A merge sort implementation recursively sorts two halves of an array and then merges the halves in linear time. What is the resulting asymptotic running time?

  1. A

    O(log⁡n)O(\log n)

  2. B

    O(n)O(n)

  3. C

    O(n2)O(n^2)

  4. D

    O(nlog⁡n)O(n\log n)

16
Choose one
1 point

The naive recursive Fibonacci function makes repeated calls for the same inputs. Which change described in the material reduces its running time to O(n)O(n)?

  1. A

    Store previously computed results with memoization

  2. B

    Remove both recursive calls and return 0

  3. C

    Increase the recursion depth limit

  4. D

    Make each recursive call use the same argument

17
True or false
1 point

True or false: In Python, making a recursive call the final operation of a function generally prevents additional stack frames from accumulating.

  1. A

    True

  2. B

    False

18
Written response
1 point

Using the recursive definition of factorial in the material, what value does factorial(5) return?

19
Written response
1 point

What proof method establishes recursive algorithm correctness by proving a base case and then showing that correctness for smaller inputs implies correctness for the current input?

20
Written response
1 point

Consider a linked-list function that returns 0 for an empty node and otherwise returns 1 + length(node.next). What recursion pattern does this function use?