Question

Question 18 CLO3 Analyze the following code and answer the questions that follow def F(n): If n <= 1: return n else: return F
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Let, F(n) be the nth fibonacci number. F(0) = 0, F(1) = 1 and F(n) = F(n - 1) + F(n - 2) and say G(n) be the no. of operations or the function call of F(n) then G(0) = G(1) = 1 and it is derived that G(n) = 2 * F(n + 1) - 1 because here we considered F(0) = 0, F(1) = 1

a. For calculating F(0),F(1)...F(6) we need 2 * (1 + 1 + 2 + 3 + 5 + 8 + 13) - 7 = 59 operations

b. if n = 7 then we need 2 * F(8) - 1 = 2 * 21 - 1 = 41 operations.

c. Complexity of the algorithm is O(2^n) because at most two functions are being called in each function call.

Add a comment
Know the answer?
Add Answer to:
Question 18 CLO3 Analyze the following code and answer the questions that follow def F(n): If n <= 1: return n else: return F(n-1)+F(n-2) for i in range (n) print (F(i)) Result: 0 1 1 2 3 5 8...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT