InfyTQ Recursion Quiz 1

Question 1

Time: 00:00:00
 Which answer is a correct skeleton for a recursive Java method?

int solution( int N ) {   if ( base case )   {     return something    }   else   {     divide problem into pieces     return something calculated from the solution to each piece     } }

int solution( int N ) {   if ( base case )   {     return something    }   else   {     divide problem into pieces     return something calculated from the solution to each piece     } }

int solution( int N ) {   if ( base case )   {     return something easily computed   }   else   {     return solution(N)     } }

int solution( int N ) {   if ( base case )   {     return something easily computed   }   else   {     return solution(N)     } }

int solution( int N ) {   divide problem into pieces   return something calculated from the solution to each piece   }

int solution( int N ) {   divide problem into pieces   return something calculated from the solution to each piece   }

int solution( int N ) {   divide problem into pieces     if ( base case )   {     return something easily computed   }   else   {     return something calculated from the solution to each piece     } }

int solution( int N ) {   divide problem into pieces     if ( base case )   {     return something easily computed   }   else   {     return something calculated from the solution to each piece     } }

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
Which line do you think has  the recursive call?







1

2

3

4

5

6
public static int factorial(int n)

{

   if (n == 0)

      return 1;

   else return n * factorial(n-1);

}

1

1

3

3

4

4

5

5

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
 Which line has the recursive call?







1

2

3

4

5

6

7

8
public String starString(int n)

{

   if (n == 0) {

      return "*";

   } else {

      return starString(n - 1) + starString(n - 1);

   }

}

1

1

3

3

4

4

5

5

6

6

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
Consider square numbers defined as follows (for positive integers):

square(1) = 1

square(N) = square(N-1) + 2N -1

According to this definition, what is square(3)?

square(3) = square(2) + square(1)

square(3) = square(2) + square(1)

square(3) = square(2) - 2*3 +1

square(3) = square(2) - 2*3 +1

square(3) = square(2) + 2*3 -1

square(3) = square(2) + 2*3 -1

square(3) = square(3) + 2*3 -1

square(3) = square(3) + 2*3 -1

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
What are two ways to view recursion?

 (i) static view, and (ii) dynamic view.

 (i) static view, and (ii) dynamic view.

 (i) recursive view, and (ii) iterative view

 (i) recursive view, and (ii) iterative view

(i) math view, and (ii) programming view

(i) math view, and (ii) programming view

 (i) code view, and (ii) translation view

 (i) code view, and (ii) translation view

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
How many recursive calls does the following method contain?







1

2

3

4

5

6

7

8
public static int multiplyEvens(int n)

{

   if (n == 1) {

      return 2;

   } else {

      return 2 * n * multiplyEvens(n - 1);

   }

}

1

1

2

2

3

3

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
Which of these will happen if the recursive method does not have a base case?

An infinite loop occurs

An infinite loop occurs

System stops the program after some time

System stops the program after some time

After 1000000 calls it will be automatically stopped.

After 1000000 calls it will be automatically stopped.

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
 Which of these packages contains the exception Stack Overflow in Java?

 java.lang

 java.lang

java.util

java.util

java.io

java.io

java.system

java.system

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
What is the output of this program?

1.class recursion {

  1. int fact(int n) {

  2.   int result;

  3.   if (n == 1)

  4.       return 1;

  5.   result = fact(n – 1) * n;

  6.   return result;

  7. }


9.}

10.class Output {

  1. public static void main(String args[]) {

  2.   recursion obj = new recursion() ;

  3.   System.out.print(obj.fact(5));

  4. }


15.}

24

24

30

30

120

120

720

720

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
What is the output of this program?

1.class recursion {

  1. int fact(int n) {

  2.   int result;

  3.   if (n == 1)

  4.       return 1;

  5.   result = fact(n – 1) * n;

  6.   return result;

  7. }


9.}

10.class Output {

  1. public static void main(String args[]) {

  2.   recursion obj = new recursion() ;

  3.   System.out.print(obj.fact(1));

  4. }


15.}

1

1

30

30

120

120

Runtime Error

Runtime Error

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Completed

0/0

Accuracy

0%