lecture9.ppt - Introduction to Algorithms Lecture 9 Last Time • Dynamic programming – Matrix Chain Multiplication – Longest common subsequence –

# lecture9.ppt - Introduction to Algorithms Lecture 9 Last...

• Notes
• 32

This preview shows page 1 - 12 out of 32 pages.

Introduction to Algorithms Lecture 9
2 Last Time Dynamic programming Matrix Chain Multiplication Longest common subsequence Optimal BST
3 Today’s Lecture Amortized Analysis Aggregate Method Accounting Method Potential Method Binary Counter Table Update
4 Amortized Analysis Scenario: Maintaining data structure over a sequence of n operation o 1 , o 2 , …, o n . Operation cost: Cost per operation may be large (e.g. ( n ) ), worst-case cost = max c ( o i ) . Total cost: But total cost may not be as much as n (worst-case cost of one operation). Amortized analysis: How to do tight analysis in such scenarios? (Total cost/ n ) Examples : Heapify vs. Build-Heap. 1 n i i c
5 Three techniques Today we will describe three techniques that can be used to analyze such scenarios. Aggregate method Accounting method Potential method Motivate by the “Binary Counter” example. Explain the differences. Move to “Dynamic Table” problem.
6 Binary Counter Data Structure: k -bit array, counting numbers from 0 to 2 k – 1 . Operation: Increment. Cost: # of bits flipped. (Toy problem! Motivates the ideas clearly!) Example: 00000 00001 Cost = 1 00010 Cost = 2 00011 Cost = 1 00100 Cost = 3
7 Aggregate method Idea: Count the total cost for n operations directly. Technique: Ad-hoc. Possibly try to count from a different way.
8 Example of Aggregate method Cost = 1 Cost = 2 Cost = 1 Cost = 3 Cost = 1 Cost = 5 Cost 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 1 1 1 1 1 16 8 4 2 1
9 Aggregate method (cont.) Count per row varies. Hard to sum up. Instead count by columns. i.e., count how many times i th bit is flipped. Add the costs. For a sequence of n increments: i th l.s.b. flipped n /2 i times.
10 Aggregate method (cont.) Total Cost = Thus total cost = O ( n ) . Amortized cost per insertion = O ( n )/ n = O (1) . n i i n 2 log 0 2 / n n n i i n i i 2 2 / 1 2 / 0 log 0 2
11 Amortized cost Definition: Average cost of an operation over a sequence of n operations, maximized over all n and all sequences.

#### You've reached the end of your free preview.

Want to read all 32 pages?

• Fall '05
• RudolfFleischer

### 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