Question 1
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 ) { 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 } }
Good Job!
Oops!
correct skeleton for a recursive Java method
int solution( int N ) { if ( base case ) { return something easily computed } else { divide problem into pieces return something calculated from the solution to each piece } }
Please login to submit your explanation
You can check your performance of this question after Login/Signup
Start
Question 2
1 public static int factorial(int n) 2 { 3 if (n == 0) 4 return 1; 5 else return n * factorial(n-1); 6 }
1
3
4
5
Line 5 because in line 5 there was a recursive call and a method calls itself to solve some problem.
Question 3
public String starString(int n) { if (n == 0) { return "*"; } else{ return starString(n - 1) + starString(n - 1); } }
6
Line 5 method calls itself to solve some problem.
Question 4
square(1) = 1 square(N) = square(N-1) + 2N -1
square(3) = square(2) + square(1)
square(3) = square(2) - 2*3 +1
square(3) = square(2) + 2*3 -1
square(3) = square(3) + 2*3 -1
Function for finding square -square(N) = square(N-1) + 2N -1 So ...square(3) = square(3-1) + 2*3 -1
Question 5
(i) static view, and (ii) dynamic view.
(i) recursive view, and (ii) iterative view
(i) math view, and (ii) programming view
(i) code view, and (ii) translation view
Their are Two ways to view recursion is static view dynamic view
Question 6
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 }
2
Output will be 1 according to code
Question 7
An infinite loop occurs
System stops the program after some time
After 1000000 calls it will be automatically stopped.
None of the mentioned
An infinite call will occur if the recursive function does not have any base case
Question 8
java.lang
java.util
java.io
java.system
Java.lang packages contains the exception Stack Overflow in Java
Question 9
24
30
120
720
Factorial of 5 is 120
Question 10
Runtime Error
Factorial of 1 is 1
Please login to report
Login/Signup
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
March 26, 2021