+1(251)732-3555 Support@tutorsgallery.com
Select Page

Assignment #2

Never use plagiarized sources. Get Your Original Essay on
Computer Science Assignment
Hire Professionals Just from \$11/Page

Computer Programming II (CS141)

Last date of submission – 11:59PM, 16th 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?

Need a custom written plagiarism free essay? Click here to order now.

Hello, Welcome to our WhatsApp support. Reply to this message to start a chat.