wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP Computer Science A Recursive

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

When the base case is met, which of these could be returned?

[Enclosing method: recursiveFunc(int n)]

a)

return recursiveFunc(n + 1);

b)

return (double) 1000;

c)

return n * recursiveFunc(n);

d)

return recursiveFunc(n) - 1;

2.

The capabilities of a recursive function can typically be recreated by . . .

a)

If / Else statements

b)

Classes

c)

Loops

d)

Interfaces

3.

For which of these operations is a recursive function practical?

a)

Scanning user input

b)

Finding the sum of two integers

c)

Returning the first item of a list

d)

Calculating the factorial of an integer

4.

What is a recursive function?

a)

Function that returns once

b)

Function that creates objects

c)

Function that calls itself

d)

Function needing abstraction to be used

5.

Which of these is NOT an acceptable header for a recursive function?

a)

public void recursiveFunc(Object obj) {

b)

public int recursiveFunc(int n) {

c)

public double recursiveFunc(double n) {

d)

public String recursiveFunc(String str) {

6.

Assuming n is initialized as an integer variable with a positive value, what will be printed?

a)

The factorial of n

b)

The absolute value of n

c)

The sum of all digits in n

d)

The square root of n

7.

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.)

a)

recursiveCollatz1(int n)

b)

recursiveCollatz2(int n)

c)

recursiveCollatz(int n)

d)

None

8.

Which of the above methods correctly implements indirect recursion?

Select all answers that apply.

a)

recursiveCollatz1(int n)

b)

recursiveCollatz2(int n)

c)

recursiveCollatz(int n)

d)

None

9.

Which of the above methods correctly implements direct recursion?

Select all answers that apply.

a)

recursiveCollatz1(int n)

b)

recursiveCollatz2(int n)

c)

recursiveCollatz(int n)

d)

None

10.

Which of the above methods could result in a stack overflow exception for certain values of n?

Select all answers that apply.

a)

recursiveCollatz1(int n)

b)

recursiveCollatz2(int n)

c)

recursiveCollatz(int n)

d)

None