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

CS141 - JAVA Please I need full answer for each question by today ==============

ID: 673584 • Letter: C

Question

CS141 - JAVA

Please I need full answer for each question by today

==================================

Q1)

A) How many recursive calls are made from the call to fib (4) (not counting the original call)?

   int fib(int n) {    // assumes n >= 0

   if (n <= 1)

      return n;

else

return (fib(n - 1) + fib(n - 2));

}

-----------

B) Identify the recursive condition in the following code.

   int fib(int n) {    // assumes n >= 0

   if (n <= 1)

   return n;

else

return (fib(n - 1) + fib(n - 2));

}

---------------

C) Why does the best recursive method usually run slightly slower than its iterative counterpart

==============================================================================

Q2:

Consider the factorial function: n! = n*(n-1)*(n-2)*...*1. Write a java code ofthe Factorial method by considering recursion?

================================================================================

Q3:

Explain and draw the UML symbols for the following terms:

- Inheritance

- Aggregation

- Dependency

- Association

============================================================================

Q4:

Draw the UML and state diagram for an ATM.

Explanation / Answer

1A: Only two recursive calls will be made because there is no looping.

1B: The recursive condition is if !(n<=1)

1C: Because Recursion is slightly complex when compared to iteration. Iteration is easy to handle for the control.

If a question has subparts we are told to answer only 2 subparts. I have answered 3.