Log in
Sign up for FREE
arrow_back
Library

Recursion Test

star
star
star
star
star
Last updated almost 2 years ago
20 questions
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?

Question 2
2.

Question 3
3.

Question 4
4.

Question 5
5.

Question 6
6.

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);
}

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);
}

Question 9
9.

Question 10
10.

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;
}

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;
}

Question 13
13.

Question 14
14.

Question 15
15.

Question 16
16.

Question 17
17.

Question 18
18.

Question 19
19.

Question 20
20.

break
shut it down
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)?
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 );
}
102
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?
2
What is returned the call fun(6) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x + fun(x - 1);
}
29
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);
}
29
13
17
26
31
21
17
31
13
26
21
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);
}
25
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);
}
20
11
16
17
18
15
18
11
16
17
15
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;
}
18
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);
}
1
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;
}
21
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;
}
21
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);
}
4
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;
}
14
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 summing all of the numbers in ray.
The method is counting the number of occurrences of x in ray.
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 averaging all of the numbers in ray.
The method is counting the number of odd numbers in ray.