Definitions Aggregate Analysis Method Accounting Method Potential Method

Definitions aggregate analysis method accounting

This preview shows page 25 - 32 out of 41 pages.

Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings The Potential Method : Stack Operations Amortized cost ˆ c i of a MULTIPOP at i th operation: Suppose that k = min { k , s } objects are popped off the stack. Actual cost is k Φ( D i ) - Φ( D i - 1 ) = - k ˆ c i = c i + Φ( D i ) - Φ( D i - 1 ) = k - k = 0 Similarly, the amortized cost of an ordinary POP operation is 0. COMP6651- Algorithm Design - Fall 2013 25
Image of page 25
. . Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings Incrementing a binary counter b i = potential of the counter after the ith INCREMENT operation = number of 1’s in the counter after the ith operation . Amortized cost of an INCREMENT operation: Suppose that the i th INCREMENT resets t i bits. Actual cost c i of the operation is at most t i + 1 since in addition to resetting t i bits it sets at most one bit to 1. { if b i = 0 , the i th operation resets all the k bits: b i - 1 = t i = k if b i > 0 b i b i - 1 - t i + 1 In either cases: b i b i - 1 - t i + 1 Potential difference: Φ( D i ) - Φ( D i - 1 ) ( b i - 1 - t i + 1 ) - b i - 1 = 1 - t i . Amortized cost ˆ c i of an INCREMENT operation: ˆ c i = c i + Φ( D i ) - Φ( D i - 1 ) ( t i + 1 ) + ( 1 - t i ) 2 . COMP6651- Algorithm Design - Fall 2013 26
Image of page 26
. . Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings Incrementing a Binary Counter If the counter starts at zero: Φ( D 0 ) = 0. Since Φ( D i ) 0 for all i , the total amortized cost of a sequence of n INCREMENT operations is an upper bound on the total actual cost Amortized cost of n INCREMENT operations is 2 n . an upper bound on the actual cost of n INCREMENT operations is O ( n ) . COMP6651- Algorithm Design - Fall 2013 27
Image of page 27
. . Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings Dynamic Tables COMP6651- Algorithm Design - Fall 2013 28
Image of page 28
. . Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings How Large Should a Hash Table Be? Goal: Make the table as small as possible, but large enough so that it will not overflow (or otherwise it becomes inefficient) Problem: What is we do not know the proper size in advance? Solution: Dynamic tables Idea: Whenever the table overflows, “grow” it by allocating a new, larger table. Move all items from the old table into the new one, and free the storage for the old table. COMP6651- Algorithm Design - Fall 2013 29
Image of page 29
. . Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings Dynamic Table Parameters Load Factor: NUM / SIZE , where NUM = # stored items SIZE = allocated size If SIZE = 0, then NUM = 0 Never allow Load Factor > 1 Keep Load Factor > constant fraction COMP6651- Algorithm Design - Fall 2013 30
Image of page 30
. . Definitions . . . . . . . . . . Aggregate Analysis Method . . . . . . Accounting Method . . . . . . . Potential Method . . . . . . . . . . . . . Dynamic Tables . Readings Dynamic Tables - Table Extension If a table T implemented as an array becomes too small, we can : allocate a new larger table T , copy the old table T into T , and delete T .
Image of page 31
Image of page 32

You've reached the end of your free preview.

Want to read all 41 pages?

  • Fall '09
  • Analysis of algorithms, Multipop, Stack Operations

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 You can ask (will expire )
Answers in as fast as 15 minutes