chap17-solutions - Selected Solutions for Chapter 17:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Selected Solutions for Chapter 17: Amortized Analysis Solution to Exercise 17.1-3 Let c i D cost of i th operation. c i D ( i if i is an exact power of 2 ; 1 otherwise : Operation Cost 1 1 2 2 3 1 4 4 5 1 6 1 7 1 8 8 9 1 10 1 : : : : : : n operations cost n X i D 1 c i ± n C lg n X j D 0 2 j D n C .2n N 1/ < 3n : (Note: Ignoring floor in upper bound of P 2 j .) Average cost of operation D Total cost # operations < 3 . By aggregate analysis, the amortized cost per operation D O.1/ . Solution to Exercise 17.2-2 Let c i D cost of i th operation.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
17-2 Selected Solutions for Chapter 17: Amortized Analysis c i D ( i if i is an exact power of 2 ; 1 otherwise : Charge each operation $3 (amortized cost y c i ). ± If i is not an exact power of 2, pay $1, and store $2 as credit. ± If i is an exact power of 2, pay $ i , using stored credit. Operation Cost Actual cost Credit remaining 1 3 1 2 2 3 2 3 3 3 1 5 4 3 4 4 5 3 1 6 6 3 1 8 7 3 1 10 8 3 8 5 9 3 1 7 10 3 1 9 : : : : : : : : : : : : Since the amortized cost is $3 per operation, n X i D 1 y c i D 3n .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

chap17-solutions - Selected Solutions for Chapter 17:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online