CS4311 Design and Analysis of Algorithms. Lecture 14: Amortized Analysis I

Similar documents
About this lecture. Three Methods for the Same Purpose (1) Aggregate Method (2) Accounting Method (3) Potential Method.

Lecture 7. Analysis of algorithms: Amortized Analysis. January Lecture 7

COMP251: Amortized Analysis

CS473-Algorithms I. Lecture 12. Amortized Analysis. Cevdet Aykanat - Bilkent University Computer Engineering Department

Unit 6: Amortized Analysis

CMSC 441: Design & Analysis of Algorithms

> asympt( ln( n! ), n ); n 360n n

1 Solutions to Tute09

Homework #4. CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class

Outline for this Week

Successor. CS 361, Lecture 19. Tree-Successor. Outline

Splay Trees. Splay Trees - 1

3/7/13. Binomial Tree. Binomial Tree. Binomial Tree. Binomial Tree. Number of nodes with respect to k? N(B o ) = 1 N(B k ) = 2 N(B k-1 ) = 2 k

Outline for this Week

Max Registers, Counters and Monotone Circuits

Lecture 5: Tuesday, January 27, Peterson s Algorithm satisfies the No Starvation property (Theorem 1)

CS 237: Probability in Computing

Smoothed Analysis of Binary Search Trees

Node betweenness centrality: the definition.

CSE 100: TREAPS AND RANDOMIZED SEARCH TREES

x is a random variable which is a numerical description of the outcome of an experiment.

Sublinear Time Algorithms Oct 19, Lecture 1

Priority Queues 9/10. Binary heaps Leftist heaps Binomial heaps Fibonacci heaps

Heaps. Heap/Priority queue. Binomial heaps: Advanced Algorithmics (4AP) Heaps Binary heap. Binomial heap. Jaak Vilo 2009 Spring

Lecture 8 Feb 16, 2017

Heaps

Design and Analysis of Algorithms 演算法設計與分析. Lecture 9 November 19, 2014 洪國寶

COSC160: Data Structures Binary Trees. Jeremy Bolton, PhD Assistant Teaching Professor

Introduction to Greedy Algorithms: Huffman Codes

PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley

SET 1C Binary Trees. 2. (i) Define the height of a binary tree or subtree and also define a height balanced (AVL) tree. (2)

Algorithms PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. binary heaps d-ary heaps binomial heaps Fibonacci heaps

Advanced Algorithmics (4AP) Heaps

CSE 417 Dynamic Programming (pt 2) Look at the Last Element

ECON 459 Game Theory. Lecture Notes Auctions. Luca Anderlini Spring 2017

Design and Analysis of Algorithms. Lecture 9 November 20, 2013 洪國寶

AVL Trees. The height of the left subtree can differ from the height of the right subtree by at most 1.

CS599: Algorithm Design in Strategic Settings Fall 2012 Lecture 6: Prior-Free Single-Parameter Mechanism Design (Continued)

The potential function φ for the amortized analysis of an operation on Fibonacci heap at time (iteration) i is given by the following equation:

CSE 21 Winter 2016 Homework 6 Due: Wednesday, May 11, 2016 at 11:59pm. Instructions

Design and Analysis of Algorithms 演算法設計與分析. Lecture 8 November 16, 2016 洪國寶

15-451/651: Design & Analysis of Algorithms October 23, 2018 Lecture #16: Online Algorithms last changed: October 22, 2018

Lecture l(x) 1. (1) x X

Vertical Asymptotes. We generally see vertical asymptotes in the graph of a function when we divide by zero. For example, in the function

Maximum Contiguous Subsequences

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

1 Binomial Tree. Structural Properties:

Discrete Mathematics for CS Spring 2008 David Wagner Final Exam

Decision Trees: Booths

It is used when neither the TX nor RX knows anything about the statistics of the source sequence at the start of the transmission

2 all subsequent nodes. 252 all subsequent nodes. 401 all subsequent nodes. 398 all subsequent nodes. 330 all subsequent nodes

COMP Analysis of Algorithms & Data Structures

15-451/651: Design & Analysis of Algorithms November 9 & 11, 2015 Lecture #19 & #20 last changed: November 10, 2015

Lecture 9 Feb. 21, 2017

Advanced Numerical Methods

4 Martingales in Discrete-Time

Lecture 6. 1 Polynomial-time algorithms for the global min-cut problem

CS 188 Fall Introduction to Artificial Intelligence Midterm 1. ˆ You have approximately 2 hours and 50 minutes.

Binary Tree Applications

Binary and Binomial Heaps. Disclaimer: these slides were adapted from the ones by Kevin Wayne

CS 237: Probability in Computing

Options and Derivatives

Issues. Senate (Total = 100) Senate Group 1 Y Y N N Y 32 Senate Group 2 Y Y D N D 16 Senate Group 3 N N Y Y Y 30 Senate Group 4 D Y N D Y 22

PARELLIZATION OF DIJKSTRA S ALGORITHM: COMPARISON OF VARIOUS PRIORITY QUEUES

1 Online Problem Examples

NOTES ON FIBONACCI TREES AND THEIR OPTIMALITY* YASUICHI HORIBE INTRODUCTION 1. FIBONACCI TREES

Structural Induction

SECTION 4.4: Expected Value

Chapter 7 One-Dimensional Search Methods

A t S + b r t T B (h i + 1) (t S + t T ) C h i (t S + t T ) + t S + b t T D (h i + n) (t S + t T )

Introduction to Fall 2007 Artificial Intelligence Final Exam

Financial Economics. Runs Test

Design and Analysis of Algorithms

UNIT VI TREES. Marks - 14

Stratification Analysis. Summarizing an Output Variable by a Grouping Input Variable

The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

Algorithmic Game Theory and Applications. Lecture 11: Games of Perfect Information

On the Optimality of a Family of Binary Trees Techical Report TR

Recall: Data Flow Analysis. Data Flow Analysis Recall: Data Flow Equations. Forward Data Flow, Again

MATH 112 Section 7.3: Understanding Chance

Outline for today. Stat155 Game Theory Lecture 13: General-Sum Games. General-sum games. General-sum games. Dominated pure strategies

6.854J / J Advanced Algorithms Fall 2008

Finding Equilibria in Games of No Chance

Multinomial Coefficient : A Generalization of the Binomial Coefficient

The following content is provided under a Creative Commons license. Your support

Q1. [?? pts] Search Traces

Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay

Data Analysis and Statistical Methods Statistics 651

Lecture 19: March 20

PAULI MURTO, ANDREY ZHUKOV. If any mistakes or typos are spotted, kindly communicate them to

Chapter 8 Statistical Intervals for a Single Sample

Probability. An intro for calculus students P= Figure 1: A normal integral

Their opponent will play intelligently and wishes to maximize their own payoff.

Priority queue. Advanced Algorithmics (6EAP) Binary heap. Heap/Priority queue. Binomial heaps: Merge two heaps.

CSCE 750, Fall 2009 Quizzes with Answers

Optimization Methods. Lecture 16: Dynamic Programming

Chapter 16. Binary Search Trees (BSTs)

Abstract stack machines for LL and LR parsing

Revenue optimization in AdExchange against strategic advertisers

AMS 7 Sampling Distributions, Central limit theorem, Confidence Intervals Lecture 4

Transcription:

CS43 Design and Analysis of Algorithms Lecture 4: Amortized Analysis I

About this lecture Given a data structure, amortized analysis studies in a sequence of operations, the average time to perform an operation Introduce amortized cost of an operation Three Methods for the Same Purpose () Aggregate Method (2) Accounting Method (3) Potential Method This Lecture 2

Super Stack Your friend has created a super stack, which, apart from PUSH/POP, supports: SUPER-POP(k): pop top k items Suppose SUPER-POP never pops more items than current stack size The time for SUPER-POP is O(k) The time for PUSH/POP is O() 3

Super Stack Suppose we start with an empty stack, and we have performed n operations But we don t know the order Questions: Worst-case time of a SUPER-POP? Ans. O(n) time [why?] Total time of n operations in worst case? Ans. O(n 2 ) time [correct, but not tight] 4

Super Stack Though we don t know the order of the operations, we still know that: There are n PUSH/POP Time spent on PUSH/POP = O(n) # items popped by all SUPER-POP cannot exceed total # items ever pushed into stack Time spent on SUPER-POP = O(n) So, total time of n operations = O(n)!!! 5

Amortized Cost So far, there are no assumptions on n and the order of operations. Thus, we have: For any n and any sequence of n operations, worst-case total time = O(n) We can think of each operation performs in average O(n) / n = O() time We say amortized cost = O() per operation (or, each runs in amortized O() time) 6

Amortized Cost In general, we can say something like: OP runs in amortized O(x) time OP 2 runs in amortized O(y) time OP 3 runs in amortized O(z) time Meaning: For any sequence of operations with #OP = n, #OP 2 = n 2, #OP 3 = n 3, worst-case total time = O(n x + n 2 y + n 3 z) 7

Binary Counter Let us see another example of implementing a k-bit binary counter At the beginning, count is, and the counter will be like (assume k=5): which is the binary representation of the count 8

Binary Counter When the counter is incremented, the content will change Example: content of counter when: count = 5 cost = 2 count = 6 The cost of the increment is equal to the number of bits flipped 9

Special case: Binary Counter When all bits in the counter is, an increment resets all bits to count = MAX cost = k count = The cost of the corresponding increment is equal to k, the number of bits flipped

Binary Counter Suppose we have performed n increments Questions: Worst-case time of an increment? Ans. O(k) time Total time of n operations in worst case? Ans. O(nk) time [correct, but not tight]

Binary Counter Let us denote the bits in the counter by b, b, b 2,, b k-, starting from the right b 4 b 3 b 2 b b Observation: b i is flipped only once in every 2 i increments Precisely, b i is flipped at x th increment x is divisible by 2 i 2

Amortized Cost So, for n increments, the total cost is: i= to k b n / 2 i c i= to k ( n / 2 i ) 2n By dividing total cost with #increments, amortized cost of increment = O() 3

Aggregate Method The computation of amortized cost of an operation in super stack or binary counter follows similar steps:. Find total cost (thus, an aggregation ) 2. Divide total cost by #operations This method is called Aggregate Method 4

Remarks In amortized analysis, the amortized cost to perform an operation is computed by the average over all performed operations There is a different topic called averagecase analysis, which studies average performance over all inputs Both are useful, but they just study different things 5

Example: Average-Case Analysis Consider building a binary search tree for n numbers with random insertion order Final height varies on insertion order Suppose each of the n! possible insertion orders is equally likely to be chosen Then, we may be able to compute the average height of the tree average is over all insertion orders 6

Example: Average-Case Analysis In fact, we can show that average height = (log n) and very likely, height = (log n) So, we can say average search time = (log n) However, we cannot say amortized search time = (log n) why? 7