Profile the performance of the memoized version of the Fibonacci function defined in Project 6. The function should count the number of recursive calls. State its computational complexity using big-O notation, and justify your answer. The fib function header has been modified to include the counter as the second parameter. Define the Counter class, it should have three methods: __init__, increment, and __str__. When an instance of the Counterclass is passed as a parameter, the countproperty of that instance should be incremented based on the number of recursive calls. The __str__ method should return the countproperty's value as a string. Please can you change the solution to this problem here, because this is wrong. """ File: fib.py Project 11.7 Employs memoization to improve the efficiency of recursive Fibonacci. Counts the calls and displays the results.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Profile the performance of the memoized version of the Fibonacci function defined in Project 6. The function should count the number of recursive calls. State its computational complexity using big-O notation, and justify your answer.

The fib function header has been modified to include the counter as the second parameter.

Define the Counter class, it should have three methods: __init__, increment, and __str__. When an instance of the Counterclass is passed as a parameter, the countproperty of that instance should be incremented based on the number of recursive calls. The __str__ method should return the countproperty's value as a string.

Please can you change the solution to this problem here, because this is wrong.

"""
File: fib.py
Project 11.7

Employs memoization to improve the efficiency of recursive Fibonacci.
Counts the calls and displays the results.
"""

class Counter(object):
def__init__(self,count=0):
self.count=count
defincrement(self):
self.count+=1
def__str__(self):
return"Number of recursive calls: "+str(self.count)
def fib(n,counter=None):
table={}
 
defmemoizeFib(n):
counter.increment()
if n<3:
return1
else:
value=table.get(n,None)
if value:return value
else:
value=memoizeFib(n)+memoizeFib(n)
table[n]=value
return value
return memoizeFib(n)

def main():
counter=Counter()
problemSize=2
print("%4s%12s"% ("n","fib(n)"))
for count inrange(5):
print("%4s%12s"% (problemSize,fib(problemSize,counter)))
print(counter)
 
if __name__ == "__main__":
main()

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

hi,it is wrong agai n      fib(n)
   2           1
   2           1
   2           1
   2           1
   2           1
Number of recursive calls: 5

 

but have to:

 

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY