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.
The 20 questions
-
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
-
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
-
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
-
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
-
What is 5! (factorial of 5)?
- 60
- 25
- 15
- 120
-
What does the recursive function fact(n) return when n = 0, given the base case fact(0) = 1?
- 0
- 1
- It loops forever
- n
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
Related quizzes
- Data types Quiz · 4.1.1.1 · 20 questions
- Programming concepts: sequence, selection and iteration Quiz · 4.1.1.2 · 20 questions
- Arithmetic operations Quiz · 4.1.1.3 · 20 questions
- Relational and Boolean operations Quiz · 4.1.1.4 · 20 questions
- Constants and variables Quiz · 4.1.1.6 · 20 questions
- String-handling operations Quiz · 4.1.1.7 · 20 questions
- Random numbers and exception handling Quiz · 4.1.1.8 · 20 questions
- Subroutines Quiz · 4.1.1.10 · 20 questions
- Parameters and returning values Quiz · 4.1.1.11 · 20 questions
- Local and global variables Quiz · 4.1.1.13 · 20 questions