Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA language thank you! Question 1 Use the formula on Slide 20 from the lect

ID: 3698225 • Letter: I

Question

In JAVA language thank you!

Question 1

Use the formula on Slide 20 from the lecture notes.

How many calls are needed to recursively calculate the Fibonacci value of 7?

In other words, how many calls to F are needed to calculate F(7)?

Answer:

Question 2

The following method should return true if the int parameter is even and either positive or 0, and false otherwise.

Which set of code should you use to replace … so that the method works appropriately?

public boolean evenPosZero(int x) {

if(x<0) return false;

… // ??? what goes here

}

Select one:

a.else if (x = = 0) return true;
else return evenPosZero(x – 1);

b.else if (x = = 0) return false;
else return evenPosZero(x – 1);

c.else return(x = = 0);

d.else if (x = = 0) return false;
else return evenPosZero(x – 2);

e.else if (x = = 0) return true;
else return evenPosZero(x – 2);

Question 3

What does the following recursive method determine if initially invoked with j=0?

public boolean whoKnows(int[ ]a, int[ ] b, int j) {

if (j = = a.length)

return false;

else if (j = = b.length)

return true;

else return

whoKnows(a, b, j+1);

}

Select one:

a.Returns true if the size of a is greater than the size of b, false otherwise

b.Returns the length of array a + length of array b

c.Returns true if the size of b is greater than the size of a, false otherwise

d.Returns true if a and b are equal in size, false otherwise

e.Returns true if a and b have no elements

Question 4

Why will the following method have infinite recursion?

public int infiniteRecursion(int n) {

if (n > 0)

return infiniteRecursion( n ) + 1;

else

return 0;

}

Select one:

a.Because there is no base case

b.Because the base case will never be true

c.Because the recursive call does not move the parameter closer to the base case

d.None of the above, there is no infinite recursion in this method

Question 5

What does the following method compute? Assume the method is called initially with i = 0

public int mysteryMethod(String a, char b, int i) {

if (i = = a.length( ))

return 0;

else if (b = = a.charAt(i))

return mysteryMethod(a, b, i+1) + 1;

else

return mysteryMethod(a, b, i+1);

}

Select one:

a.Returns 1 if char b appears in String a at least once, and 0 otherwise

b.The length of String a concatenated with char b

c.The length of String a

d.The number of times char b appears in String a

e.The char which appears at location i in String a

Question 6

The following method lacks a base case.

public int noBaseCase(int x) {

if (x > 0)

return noBaseCase(x – 1) + 1;

                else

return noBaseCase(x – 2) + 2;

}

Select one:

True

False

Question 7

The following two methods will both compute the same thing when invoked with the same value of x. That is, method1(x) = = method2(x).

public int method1(int x) {

if (x > 0)

return method1(x – 1) + 1;

else

return 0;

}

public int method2(int x) {

if (x > 0)

return 1 + method2(x – 1);

else

return 0;

}

Select one:

True

False

Explanation / Answer

1- 8
2- b
3- a
4- a
5- d
6- a
7- true
8- true

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote