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

Question 2

Time: 00:00:00
Which line do you think has  the recursive call?
1 public static int factorial(int n)
2 {
3 if (n == 0)
4 return 1;
5 else return n * factorial(n-1);
6 }

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

Question 3

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

public String starString(int n){
   if (n == 0) {
      return "*";}
else{
      return starString(n - 1) + starString(n - 1);}}

1

1

3

3

4

4

6

6

5

5

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

Please login to submit your explanation

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

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

Question 6

Time: 00:00:00
How many recursive calls does the following method contain?
1 public static int multiplyEvens(int n)
2 {
3   if (n == 1) {
4      return 2;
5   } else {
6     return 2 * n * multiplyEvens(n - 1);
7  }
8 }

1

1

2

2

3

3

5

5

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

Please login to submit your explanation

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

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

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

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

["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%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.