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(1).
private int count_i =0;
public void op1(){
int temp = count_i;
for (int i =0; i < temp; i++){
count_i = count_i -1;
}
// count_i ==0
}
public void op2(){
count_i +=7;
}
}
In this problem, you will work through the steps that comprise an amortized analysis
on MyClass. You must use the potential method
(a)(10 points) Assuming D0 is the initial state of a MyClass, and Di is the state of
the MyClass object after the i-th operation, then define (Di).
(b)(10 points) Prove that (Di)0.
(c)(10 points) What is the amortized cost of op1? Give both the non-asymptotic and
asymptotic cost. You may assume, for the sake of simplicity, that ci for op1 is the
number of times the for loop executes. Give the best possible big O and justify
your answer.
(d)(10 points) What is the amortized cost of op2? Give both the non-asymptotic 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 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!