Lesson 4.1.1.16

4.1.1.16 Recursive techniques Quiz: AQA Computer Science, Unit 1

20 questions

In partnership with Revision Ninja

Lesson 4.1.1.16, Recursive techniques: 20 multiple choice questions for the AQA Computer Science (7517), Unit 1: Fundamentals of programming, written with Revision Ninja.

Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.

Host this setFree Play

The 20 questions

  1. What is a recursive subroutine?

    • A subroutine that is never called, so it is kept in the program only as a reference for the programmer
    • A subroutine that returns a constant, so every call gives back the same fixed value each time
    • A subroutine that calls itself to solve a smaller version of the same problem
    • A subroutine that runs only once in a loop, so it never returns to its caller in any situation
  2. What are the two essential parts of a recursive solution?

    • A parameter and a global variable
    • A base case and a recursive case
    • An array and a record
    • A loop counter and a constant
  3. What is the purpose of the base case in a recursive subroutine?

    • It stores the result in a file, so that the answer can be reloaded when the program next runs
    • It starts the recursion with a larger input, so each call works on more data than the one before
    • It makes the subroutine call itself more often, so that the result is reached more quickly
    • It provides a stopping point so the calls do not continue forever
  4. Which expression is the standard recursive definition of factorial for n >= 1?

    • n! = n * n
    • n! = n + (n - 1)!
    • n! = n * (n - 1)!
    • n! = 1 for all n
  5. What is 5! (factorial of 5)?

    • 60
    • 25
    • 15
    • 120
  6. What does the recursive function fact(n) return when n = 0, given the base case fact(0) = 1?

    • 0
    • 1
    • It loops forever
    • n
  7. A recursive function sumTo(n) returns n + sumTo(n - 1) with the base case sumTo(0) = 0. What is sumTo(4)?

    • 10
    • 6
    • 24
    • 4
  8. A recursive function is written with no base case. What is the likely outcome?

    • The calls never stop and the stack eventually overflows
    • The function returns zero immediately, because a missing base case is treated as an empty result
    • The program corrects itself automatically, by adding a base case that the language supplies
    • The function calls itself exactly once, then stops, because the language limits recursion to one level
  9. Which problem is a natural fit for a recursive approach?

    • Reading one value from a file, which is a single operation with no repeated steps at all
    • Printing a single fixed line of text, which needs only one statement and no repeated work
    • Calculating the nth Fibonacci-style sequence defined in terms of earlier terms
    • Storing a constant, which is a one-off assignment that is done once when the program starts
  10. A recursive function is used to reverse a string. Which recursive step is most suitable?

    • Reverse the rest of the string, then add the first character to the end
    • Count the characters and return the number, which gives the length of the reversed string
    • Reverse only the first character, leaving the remainder of the string in its original order
    • Add the first character to the front and stop, so the string is returned with no further calls
  11. Which statement describes the difference between recursion and iteration in general?

    • Recursion uses repeated subroutine calls with stack frames, while iteration repeats a loop body
    • Recursion never needs a stopping condition, but iteration always needs one to end its loop
    • Iteration always uses more stack frames than recursion, because each pass creates a new frame
    • Recursion and iteration are identical in every respect, differing only in the names used
  12. A recursive function counts down from n to 1 and prints each value. What is printed when called with n = 3?

    • 3, 2, 1
    • 3, 3, 3
    • 2, 1
    • 1, 2, 3
  13. What is the result of power(2, 3) if power(x, n) = x * power(x, n - 1) with the base case power(x, 0) = 1?

    • 8
    • 5
    • 6
    • 9
  14. A recursive function is called with a value that never moves towards the base case. What would be a suitable correction?

    • Declare the parameter as a constant, so that the value is fixed and the function never changes it
    • Remove the base case so the calls are faster, since the stopping check uses extra processing
    • Use a larger stack frame each time, so that the recursion has more room to reach the base case
    • Change the parameter each call so it moves towards the base case
  15. Why does a recursive call need its own stack frame?

    • Recursive calls do not use parameters, so there is nothing that needs to be stored per call
    • Recursive calls share one frame to save memory, so every call uses the same set of values
    • Each pending call must keep its own parameters and return address until it finishes
    • Recursion avoids the stack entirely, storing each call in a separate file on the disk instead
  16. A recursive function is used to calculate the sum of the digits of a number. For 123, which result is correct?

    • 3
    • 5
    • 6
    • 123
  17. A recursive binary search splits a list in half each call. Roughly how many calls are needed for a list of 1024 items in the worst case?

    • About 2
    • About 10
    • About 512
    • About 1024
  18. A programmer wants to make a recursive function efficient. Which factor most affects the number of calls made?

    • The number of comments in the code, because comments are processed at each recursive call
    • The colour of the screen, which changes the speed at which the processor runs each call
    • The name of the function, since shorter names make each recursive call run more quickly
    • How quickly the input moves towards the base case
  19. Which of these shows a correct general case for a recursive function that computes the length of a string s?

    • 1 + length(rest of s), with base case length of empty string = 0
    • length(s) = 0 for every string, since the length is always reset at the start of each call
    • length(s) = length(s) with no change, so the same call is repeated until the string is empty
    • length(s) = the first character, which returns a single letter as the length of the string
  20. A recursive subroutine returns a value that is then used in an expression by its caller. Which statement is correct?

    • The caller ignores all recursive return values, so the results are discarded at each level
    • Each return passes its value back to the call that made it, so the values combine as the stack unwinds
    • Each return replaces the previous return value in memory, so only the first value is kept
    • Recursive functions can only return Boolean values, so the results are always TRUE or FALSE

All AQA Computer Science quizzes