Question: Consider the same operation - counting rules and Python program we saw in the last video's question: Each addition and subtraction costs 1 Each comparison

Consider the same operation-counting rules and Python program we saw in the last video's question:
Each addition and subtraction costs 1
Each comparison (a > b) costs 1
Everything else is free
7
def fun(n,x):
counter = n
amount =0
while counter >0:
amount = amount + x
counter = counter -1
return amount
As we saw before, the cost of calling this function, by the above rules, is 3n +1.
What is the smallest expression g such that the cost of calling the function is O(g)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!