Question: public class MyClass { / / Assume ints can get arbitrarily large but simple operations / / on them still remain worst case O (
public class MyClass
Assume ints can get arbitrarily large but simple operations
on them still remain worst case O
private int counti ;
public void op
int temp counti;
for int i ; i temp; i
counti counti ;
counti
public void op
counti ;
In this problem, you will work through the steps that comprise an amortized analysis
on MyClass. You must use the potential method
a points Assuming D is the initial state of a MyClass, and Di is the state of
the MyClass object after the ith operation, then define Di
b points Prove that Di
c points What is the amortized cost of op Give both the nonasymptotic and
asymptotic cost. You may assume, for the sake of simplicity, that ci for op is the
number of times the for loop executes. Give the best possible big O and justify
your answer.
d points What is the amortized cost of op Give both the nonasymptotic and
asymptotic cost. For your asymptotic cost, give the best possible big O Justify
your answer.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
