Question

3. Suppose we are doing a sequence of operations (numbered 1, 2,3, ..) such that the ith operation: costs 1 if i is not a pow


3. Suppose we are doing a sequence of operations (numbered 1, 2, 3, ...) such that the ith
operation:
- costs 1 if i is not a power of 2
- costs i if i is a power of 2.

For example, the following table shows the costs for each of the first few operations:
Operation 1 2 3 4 5 6 7 8 9 …
Cost 1 2 1 4 1 1 1 8 1 …
Determine the best amortized O() for this operation, using both the aggregate method and the accountig method.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

what is amortised cost using aggregate method is

amortized cost = total cost of n operation / n

so we have to just find the cost of all the operations and then add them and divide them by n

so total cost = 1+ 2+ 1 + 4 + 1 + 1 + 1+ 8 ...   

n + log(n-1)) 2 it will approx to 3n

which is equivalent to O(n)

so amortized cost = O(n) / n = O( 1)  

2.) accounting method tells that we store some cost for the cheaper actions and then use that extra cost for the heavy actions.

suppose we make a cost of 3 for every operation so what happen now look at following table

operation available cost remaining cost
1 3 3 -1 =2
2 2 + 3= 5 5 -2 =3
3 3+3= 6 6-1 =5
4 5+3 =8 8-4 =4
5 4+3 =7 7-1=6
6 6+3 =9 9-1 =8
7 8+3 =11 11-1 =10
8 10+3 =13 13-8=5

as we can see that the cost 3 is sufficient to complete the operations and it will satisfy all the requirements.

so for the n operations total cost will be 3*n  

so for one operation cost is 3 which is equivalent to O(1)

I hope this will help you so please give positive ratings :)))

Add a comment
Know the answer?
Add Answer to:
3. Suppose we are doing a sequence of operations (numbered 1, 2, 3, ...) such that the ith operation: - costs 1 if i is not a power of 2 - costs i if i is a power of 2. For example, the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT