Log in
Sign up for FREE
arrow_back
Library
Recursion Test
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated almost 2 years ago
20 questions
Add this activity
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
Question 1
1.
What do you call the condition that stops recursion?
return
stop
base case
break
shut it down
Question 2
2.
Consider the following method.
public static int myst(int i)
{
if(i<=0)
return 0;
if(i<=3)
return i;
return myst(i-2)+myst(i-1);
}
What is returned by the call
myst(5)
?
5
13
8
4
3
Question 3
3.
What is returned by the call
ben(51) ?
public static String ben(int x)
{
if( x / 5 <= 0 )
return "" + x % 5;
else
return "" + ( x % 5 ) + ben( x / 5 );
}
202
21
201
101
102
Question 4
4.
Consider the following method.
public static int alice(int m, int n)
{
if(m < 3)
return n;
return alice(n-2, m-1);
}
What value does of
alice(11, 12)
return?
12
7
3
11
2
Question 5
5.
What is returned the call
fun(6) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x + fun(x - 1);
}
16
22
37
11
29
Question 6
6.
What is returned by the call
fun(8) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x + fun(x - 1);
}
22
11
16
37
29
Question 7
7.
What is returned by the call
fun(8) ?
public static int fun(int x){
if(x < 1)
return 1;
else
return x + fun(x - 2);
}
13
17
26
31
21
Question 8
8.
What is returned by the call
fun(6) ?
public static int fun(int x){
if(x < 1)
return 1;
else
return x + fun(x - 2);
}
17
31
13
26
21
Question 9
9.
What is returned by the call
fun(1) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x - fun(x - 3);
}
0
8
12
22
25
Question 10
10.
What is returned by the call
fun(10) ?
public static int fun(int x)
{
if (x < 1)
return x;
else
return x + fun(x - 2);
}
12
0
8
30
20
Question 11
11.
What is returned by the call
wacky(5,5) ?
public static int wacky(int x, int y){
if(x <= 1)
return y;
else
return wacky(x - 1,y - 1) + y;
}
11
16
17
18
15
Question 12
12.
What is returned by the call
wacky(4,6) ?
public static int wacky(int x, int y){
if(x <= 1)
return y;
else
return wacky(x - 1,y - 1) + y;
}
18
11
16
17
15
Question 13
13.
What is returned by the call
wacky(2,6) ?
public static int wacky(int x, int y)
{
if(x <= 1)
return y;
else
return wacky(x - 1,y - 1) + y;
}
16
11
15
17
18
Question 14
14.
What is returned by the call
funny(0) ?
public static int funny(int x)
{
if(x<1)
return 1;
else
return x + funny(x - 1) - funny(x - 2);
}
2
16
13
25
1
Question 15
15.
What is returned by the call
go(2,6) ?
public static int go(int x, int y)
{
if(x <= 1)
return y;
else
return go(x - 1,y) + y;
}
16
8
12
11
21
Question 16
16.
What is returned by the call
go(4,2) ?
public static int go(int x, int y)
{
if(x <= 1)
return y;
else
return go(x - 1,y) + y;
}
8
16
11
12
21
Question 17
17.
What is returned by the call
fly(2) ?
public static int fly(int x)
{
if(x < 1)
return 1;
else
return x + fly(x - 3) - fly(x - 2);
}
25
2
17
8
4
Question 18
18.
What is returned by the call
go(7,3)?
public static int go(int x, int y)
{
if(x <= 1)
return y;
else
return go(x - 1,y) + y;
}
21
4
16
8
14
Question 19
19.
Which of the following answer choices best describes the algorithmic purpose of method ben?
public static int ben(int[] ray, int i, int x)
{
if( i >= ray.length )
return 0;
if( ray[i] == x )
return 1 + ben( ray, i+1, x );
return 0 + ben( ray, i+1, x );
}
The method is counting the number of even numbers in ray.
The method is counting the number of odd numbers in ray.
The method is counting the number of numbers in ray.
The method is summing all of the numbers in ray.
The method is counting the number of occurrences of x in ray.
Question 20
20.
Which of the following answer choices best describes the algorithmic purpose of method ben?
public static int ben(int[] ray, int i)
{
if( i >= ray.length )
return 0;
if( ray[i] % 2 == 0 )
return 1 + ben( ray, i+1 );
return 0 + ben( ray, i+1 );
}
The method is counting the number of numbers in ray.
The method is counting the number of even numbers in ray.
The method is counting the number of occurrences of x in ray.
The method is averaging all of the numbers in ray.
The method is counting the number of odd numbers in ray.