WorksheetsAP Computer Science A Recursive
Total questions: 10
Worksheet time: 10mins
When the base case is met, which of these could be returned?
[Enclosing method: recursiveFunc(int n)]
return recursiveFunc(n + 1);
return (double) 1000;
return n * recursiveFunc(n);
return recursiveFunc(n) - 1;
The capabilities of a recursive function can typically be recreated by . . .
If / Else statements
Classes
Loops
Interfaces
For which of these operations is a recursive function practical?
Scanning user input
Finding the sum of two integers
Returning the first item of a list
Calculating the factorial of an integer
What is a recursive function?
Function that returns once
Function that creates objects
Function that calls itself
Function needing abstraction to be used
Which of these is NOT an acceptable header for a recursive function?
public void recursiveFunc(Object obj) {
public int recursiveFunc(int n) {
public double recursiveFunc(double n) {
public String recursiveFunc(String str) {
Assuming n is initialized as an integer variable with a positive value, what will be printed?
The factorial of n
The absolute value of n
The sum of all digits in n
The square root of n
The Collatz Conjecture states that, in sequence, taking any integer and, if even, halving the result/integer and, if odd, tripling and adding 1 to the result/integer continuously will eventually end up as 1.
Which of the above methods properly recreates the conjecture?
Select all answers that apply.
(Click the picture to enlarge.)
recursiveCollatz1(int n)
recursiveCollatz2(int n)
recursiveCollatz(int n)
None
Which of the above methods correctly implements indirect recursion?
Select all answers that apply.
recursiveCollatz1(int n)
recursiveCollatz2(int n)
recursiveCollatz(int n)
None
Which of the above methods correctly implements direct recursion?
Select all answers that apply.
recursiveCollatz1(int n)
recursiveCollatz2(int n)
recursiveCollatz(int n)
None
Which of the above methods could result in a stack overflow exception for certain values of n?
Select all answers that apply.
recursiveCollatz1(int n)
recursiveCollatz2(int n)
recursiveCollatz(int n)
None
