Question: 1. Which statements are true about a recursive method? 1) It must contain a call to itself 2) It must contain an IF statement (or

1.

Which statements are true about a recursive method? 1) It must contain a call to itself 2) It must contain an IF statement (or some equivalent form of conditional execution).

Question 1 options:

2

Both 1 and 2

Neither 1 nor 2

1

2.

Recursion should be avoided because it is always far less efficient than an iterative (looping) solution --- for example, see the Fibonacci recursive method.

Question 2 options:

True

False

3.

A recursive myMethod(int x) is called. The method then calls itself 4 more times. How many copies of x are there?

Question 3 options:

1

2

3

4

5

6

None of these answers are correct

4.

What happens when a recursive method does not have a base condition? (Select all that apply)

Question 4 options:

When running the method, a StackOverflowError occurs

The method will not compile

The method will be called 128 times before timing out.

When running the method, infinite recursion occurs

5.

The following recursive method should find the minimum value in the first n elements of the array a.

public static double aMin(double[] a, int n){ if(n==1) return a[0]; else return ???? }

Which code would you include in the return statement to complete the method?

Question 5 options:

Math.min(a[n-1], aMin(a,n-2));

Math.min(a[0], aMin(a,n-1));

Math.min(a[0], aMin(a,n-2));

Math.min(a[n-1], aMin(a,n-1));

None of these statements would work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!