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

This preview shows page 1 - 12 out of 32 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 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
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.
Image of page 11
Image of page 12

You've reached the end of your free preview.

Want to read all 32 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

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes