Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions 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
Check Mark
Still need help?
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
by Bartleby Expert
SEE SOLUTION
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
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Engineering
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY