Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

LO2.5 Describe the mechanics of the circular flow model.

Answered: 1 week ago

Question

LO2.6 Explain how the market system deals with risk.

Answered: 1 week ago