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

lecture9-old.ppt - Introduction to Algorithms Lecture 9...

This preview shows page 1 - 14 out of 61 pages.

Introduction to Algorithms Lecture 9
Image of page 1
2 Last Time Dynamic programming Matrix Chain Multiplication Longest common subsequence Optimal BST
Image of page 2
3 Today’s Lecture Amortized Analysis Aggregate Method Accounting Method Potential Method Binary Counter Table Update
Image of page 3
4 Amortized Analysis Scenario: Maintaining data structure over a sequenc e of n operation. Operation cost: Cost per operation may be large (e.g. ( n ) ). 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? Examples: Heapify vs. Build-Heap.
Image of page 4
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.
Image of page 5
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
Image of page 6
7 Aggregate method Idea: Count the total cost for n operations directly. Technique: Ad-hoc. Possibly try to count from a different way.
Image of page 7
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
Image of page 8
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.
Image of page 9
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
Image of page 10
11 Amortized cost Definition: Average cost of an operation over a sequence of n operations, maximized over all n and all sequences. Warning: Not average case analysis! No assumptions about input sequence. Amortization is still a worst-case principle. In aggregate method, counted the total to bound the amortized cost. Usually do this the other way.
Image of page 11
12 Accounting method Data structure comes with a “bank account”. Every operation allotted a fixed $ cost (its amortized cost). If actual cost less than allotted amount, deposit extra $ ’s into bank. If actual cost more than allotted amount, withdraw from bank to pay for the operation. Prove: Always have a non-negative balance. Conclude: Sequence of n operations costs at most n times the amortized cost!
Image of page 12
13 Example: Binary Counter Amortized Cost of flipping 0 1 = 2$ . Amortized Cost of flipping 1 0 = 0$ .
Image of page 13
Image of page 14

You've reached the end of your free preview.

Want to read all 61 pages?

  • Fall '05
  • RudolfFleischer

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors