Assignment #2
Computer Programming II (CS141)
Last date of submission – 11:59PM, 11th Oct 2015
Total Marks: 5
Q.1. A) How many recursive calls are made from the call to fib (4) (not counting the original call)?
(0.5 Marks)
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.
(0.5 Marks)
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?
(0.5 Marks)
Q.2. Consider the factorial function: n! = n*(n-1)*(n-2)*...*1. Write a java code of the Factorial method by considering recursion?
(1 Mark)
Q.3. Explain and draw the UML symbols for the following terms.
i) Inheritance
ii) Aggregation
iii) Dependency
iv) Association
(0.25 x 4 = 1 Mark)
Q.4. Draw the UML and state diagram for an ATM ((UML=1 Mark, State=0.5 Marks) = 1.5 Marks)

    • 11 years ago
    QUALITY WORK
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      cs.docx