Recursion Test
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
20 Questions
5 points
5
Question 1
1.
What do you call the condition that stops recursion?
What do you call the condition that stops recursion?
5 points
5
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)?
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 points
5
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 );}
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 );
}
5 points
5
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?
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?
5 points
5
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);}
What is returned the call fun(6) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x + fun(x - 1);
}
5 points
5
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);}
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);
}
5 points
5
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);}
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);
}
5 points
5
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);}
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);
}
5 points
5
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);}
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);
}
5 points
5
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);}
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);
}
5 points
5
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;}
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;
}
5 points
5
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;}
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;
}
5 points
5
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;}
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;
}
5 points
5
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);}
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);
}
5 points
5
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;}
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;
}
5 points
5
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;}
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;
}
5 points
5
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);}
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);
}
5 points
5
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;}
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;
}
5 points
5
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 );}
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 );
}
5 points
5
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 );}
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 );
}