Preskoči na glavni sadržaj
Prijava
Sign up for FREE
arrow_back
Biblioteka

Recursion Test

star
star
star
star
star
Posljednje ažuriranje about 2 years ago
20
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
Pitanje 1
1.

What do you call the condition that stops recursion?

Pitanje 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)?

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

}

Pitanje 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?

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}