ta11_sol

ta11_sol - COMP 271H Design and Analysis of Algorithms 2006...

• Notes
• 2

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

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? Answer: We can regrad any 2 l operation is a costly operation. Assume we have used up all the

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

This is the end of the preview. Sign up to access the rest of the document.
• Spring '10
• may
• English, Analysis of algorithms, actual cost, Amortized analysis, Potential method, ci ci

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern