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

Question 7 Assume there are four methods A, B, C, and D. If method A calls metho

ID: 3829732 • Letter: Q

Question

Question 7

Assume there are four methods A, B, C, and D. If method A calls method B, method B calls method C, method C calls method D, and method D calls method A, which of the following methods is indirectly recursive?

A

B

C

D

1 points   

Question 8

Using a recursive algorithm to solve the Tower of Hanoi problem, a computer that can generate one billion moves per second would take ____ years to solve the problem.

39

400

500

10,000

1 points   

Question 9

public static int exampleRecursion (int n)
{
    if (n == 0)
         return 0;
    else
         return exampleRecursion(n - 1) + n * n * n;
}

How many base cases are in the code in the accompanying figure?

zero

one

two

three

1 points   

Question 10

public static int func1(int m, int n)
{
    if (m == n || n == 1)
        return 1;
    else
         return func1(m - 1, n - 1) + n * func1(m - 1, n);
}

Given the code in the accompanying figure, which of the following method calls would result in the value 1 being returned?

func1(1, 0)

func1(1, 1)

func1(1, 2)

func1(2, 0)

1 points   

Question 11

____ is NOT an iterative control structure.

A while loop

A for loop

Recursion

A do...while loop

1 points   

Question 12

public static int exampleRecursion (int n)
{
    if (n == 0)
         return 0;
    else
         return exampleRecursion(n - 1) + n * n * n;
}

What is the limiting condition of the code in the accompanying figure?

n >= 0

n > 0

n > 1

n >= 1

A

B

C

D

Explanation / Answer

Hi, I have answered all except Q9.


Q20)

   We are calling func1 recursively with lower m and n:
              func1(m - 1, n - 1) + n * func1(m - 1, n)
       So, we should have check : m>=0 && n >= 1

   Ans: m >= 0 and n >= 1

Q19)
   We are calling func2 recursively with lower n:
               func2(m, n - 1)

   So, it should check : n >=0 instead of n == 0

   Ans: n >= 0

Q18)
   So, we are summing up the values in list in range : first to last:

           list[first] + strange(list, first + 1, last);

       So, {2, 5, 8, 9, 13, 15, 18, 20, 23, 25}
       and: (strange(beta, 4, 7))

   Ans: 13+ 15+ 18+ 20 = 66


Q17)
   exampleRecursion(0):
           As we have: n == 0 in base condition,it returns 0

   Ans: 0


Define a function isSorted which satisfies the following claim: If xs is a List<T> where T extends Comparable<T>, then isSorted(xs) is true if and only if xs is sorted in ascending order.

public static boolean isSorted(List<T> xs){
  
   if(xs == null || xs.size() < 2)
       return true;

   for(int i=0; i<xs.size()-1; i++){
       if(xs.get(i) > xs.get(i+1))
           return false;
   }

   return true;
}


Q7)

Ans: method A is inderectly recursive

       A => B => C => D => A

Q9)
   Ans: one

   We have base case:
       if (n == 0)
    return 0;

Q10)
   Ans: func1(1, 1)

       We have base case :
           if(m==n || n==1)
               return 1;
       So, here m = 1, n = 1

Q11)
   Ans: Recursion is Not an iterative control structure.

Q12)
   Ans: n > 0

   Because we stop recursion when n = 0

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