Ta11_sol - COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 11 1(From textbook A sequence of n operations is performed on a

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 11 1. (From textbook) A sequence of n operations is performed on a data structure. The i th operation costs i if i is an exact power of 2, and 1 otherwise. Determine the amortized cost per operation in two ways: (i) using the accounting method; (ii) using the potential method. Possible solution: Define C i be the actual cost for the i th operation, we have: C i = i if i is power of 2 C i = 1 otherwise Accounting method We claim that each operation pays for 3 credits (amortized cost of ANY operation is 3), Case 1: Not the i th operation • Use 1 credit to pay for the actual cost • Save 2 credits into the account for future use Case 2: The i th operation • If i < 3, save i- 3 credits into the account for future use • Otherwise, pay i- 3 credits from the account Question: How to come up with the magic number (3 credits) for any operation?...
View Full Document

This note was uploaded on 12/09/2010 for the course ENGLISH 1303 taught by Professor May during the Spring '10 term at HKU.

Page1 / 2

Ta11_sol - COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 11 1(From textbook A sequence of n operations is performed on a

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

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