Amortized Complexity Main Idea

Similar documents
AMORTIZED ANALYSIS. binary counter multipop stack dynamic table. Lecture slides by Kevin Wayne. Last updated on 1/24/17 11:31 AM

past balancing schemes require maintenance of balance info at all times, are aggresive use work of searches to pay for work of rebalancing

Amortized Analysis (chap. 17)

Splay Trees. CMSC 420: Lecture 8

Amortized analysis. Amortized analysis

Data Structures and Algorithm. Xiaoqing Zheng

Lecture 7: Amortized analysis

CS 5321: Advanced Algorithms Amortized Analysis of Data Structures. Motivations. Motivation cont d

Tutorial 4. Dynamic Set: Amortized Analysis

Algorithms and Data Structures

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

Today: Amortized Analysis

N/4 + N/2 + N = 2N 2.

8: Splay Trees. Move-to-Front Heuristic. Splaying. Splay(12) CSE326 Spring April 16, Search for Pebbles: Move found item to front of list

Search Trees. Chapter 10. CSE 2011 Prof. J. Elder Last Updated: :52 AM

Amortized Analysis. DistributeMoney(n, k) 1 Each of n people gets $1. 2 for i = 1to k 3 do Give a dollar to a random person

Graduate Analysis of Algorithms Dr. Haim Levkowitz

Outline for Today. Static Optimality. Splay Trees. Properties of Splay Trees. Dynamic Optimality (ITA) Balanced BSTs aren't necessarily optimal!

Ch 01. Analysis of Algorithms

Priority queues implemented via heaps

Search Trees. EECS 2011 Prof. J. Elder Last Updated: 24 March 2015

Lecture 5: Splay Trees

Ch01. Analysis of Algorithms

Fast Sorting and Selection. A Lower Bound for Worst Case

Data Structures and Algorithms

Disjoint Sets : ADT. Disjoint-Set : Find-Set

CORRECTNESS OF A GOSSIP BASED MEMBERSHIP PROTOCOL BY (ANDRÉ ALLAVENA, ALAN DEMERS, JOHN E. HOPCROFT ) PRATIK TIMALSENA UNIVERSITY OF OSLO

Chapter 6. Self-Adjusting Data Structures

Algorithm Design and Analysis

Lecture 2 14 February, 2007

Lecture 1 : Data Compression and Entropy

DATA STRUCTURES I, II, III, AND IV

Graphs and Trees Binary Search Trees AVL-Trees (a,b)-trees Splay-Trees. Search Trees. Tobias Lieber. April 14, 2008

Biased Quantiles. Flip Korn Graham Cormode S. Muthukrishnan

Functional Data Structures

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Another way of saying this is that amortized analysis guarantees the average case performance of each operation in the worst case.

Splay trees (Sleator, Tarjan 1983)

Second main application of Chernoff: analysis of load balancing. Already saw balls in bins example. oblivious algorithms only consider self packet.

Amortized Complexity Verified

Algorithm Design and Analysis

Analysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes.

Inge Li Gørtz. Thank you to Kevin Wayne for inspiration to slides

Fibonacci (Min-)Heap. (I draw dashed lines in place of of circular lists.) 1 / 17

Data selection. Lower complexity bound for sorting

Lower Bounds for Dynamic Connectivity (2004; Pǎtraşcu, Demaine)

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Single Source Shortest Paths

Notes on Logarithmic Lower Bounds in the Cell Probe Model

Lecture Notes for Chapter 17: Amortized Analysis

Generating Functions and the Fibonacci Sequence

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

Price of Stability in Survivable Network Design

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Shortest Path Algorithms

Outline for Today. Static Optimality. Splay Trees. Properties of Splay Trees. Dynamic Optimality (ITA) Balanced BSTs aren't necessarily optimal!

Theory of Computing Systems 2006 Springer Science+Business Media, Inc.

Graph-theoretic Problems

Data Structures 1 NTIN066

CS361 Homework #3 Solutions

1 Terminology and setup

Problem. Maintain the above set so as to support certain

Equivalence Relations. Disjoint Union / Find. Dynamic Equivalence Problem. Equivalence Classes

MA015: Graph Algorithms

ENS Lyon Camp. Day 2. Basic group. Cartesian Tree. 26 October

Algorithms: Lecture 12. Chalmers University of Technology

1 Randomized Computation

Slides for CIS 675. Huffman Encoding, 1. Huffman Encoding, 2. Huffman Encoding, 3. Encoding 1. DPV Chapter 5, Part 2. Encoding 2

data structures and algorithms lecture 2

Algorithms. Algorithms 2.4 PRIORITY QUEUES. Pro tip: Sit somewhere where you can work in a group of 2 or 3

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 )

INF2220: algorithms and data structures Series 1

Lecture 5: Loop Invariants and Insertion-sort

8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

A C E. Answers Investigation 2. Applications. Age (wk) Weight (oz) 1. a. Accept any line that approximates the data. Here is one possibility:

in (n log 2 (n + 1)) time by performing about 3n log 2 n key comparisons and 4 3 n log 4 2 n element moves (cf. [24]) in the worst case. Soon after th

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

IS 709/809: Computational Methods in IS Research Fall Exam Review

T U M I N S T I T U T F Ü R I N F O R M A T I K. Binary Search on Two-Dimensional Data. Riko Jacob

5 ProbabilisticAnalysisandRandomized Algorithms

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Lecture 15 April 9, 2007

Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM

IE418 Integer Programming

Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.

Disjoint-Set Forests

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Union-Find Structures

Concrete models and tight upper/lower bounds

Advanced Analysis of Algorithms - Midterm (Solutions)

ERROR IN LINEAR INTERPOLATION

Data Structures for Disjoint Sets

Partially Observable Markov Decision Processes (POMDPs)

S95 INCOME-TESTED ASSISTANCE RECONCILIATION WORKSHEET (V3.1MF)

CS2223 Algorithms D Term 2009 Exam 3 Solutions

6.854 Advanced Algorithms

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

Data Structures 1 NTIN066

Homework 4 Solutions

Design and Analysis of Algorithms

Transcription:

omp2711 S1 2006 Amortized Complexity Example 1 Amortized Complexity Main Idea Worst case analysis of run time complexity is often too pessimistic. Average case analysis may be difficult because (i) it is not clear what is average data, (ii) uniformly random data is usually not average, (iii) probabilistic arguments can be difficult. Amortized complexity analysis is a different way to estimate run times. The main ideas is to spread out the cost of operations, charging more than necessary when they are cheap thereby saving up for later use when they occasionally become expensive.

omp2711 S1 2006 Amortized Complexity Example 2 The Accounting Method We choose a set (typically a singleton, but always a small set) of elementary operations whose cost can be set to a constant (typically 1, or other small constants). In running the algorithm some steps make use of just the elementary operations, others use them in combination aggregate operations. We invent an accounting or potential function φ : S N where S is the state space of the (data) structure and N is the set of natural numbers. φ(t) denotes the amount of (cyber) dollars deposited or saved up in state T.

omp2711 S1 2006 Amortized Complexity Example 3 Costs of Operations Performing operations cost dollars. Suppose an operation F maps a state T 1 to a state T 2. Let its cost be Cost F (T 1, T 2 ) dollars. If this is cheap we may decide to actually charge it more than the cost in order to save up for more expensive operations later. If so, we deposit the excess in state T 2. The dollar amounts in T 1 and T 2, i.e, respectively φ(t 1 ) and φ(t 2 ) may be different. If φ(t 1 ) > φ(t 2 ) then φ(t 1 ) φ(t 2 ) dollars is released to help meet the cost Cost F (T 1, T 2 ). If φ(t 1 ) < φ(t 2 ) there is a shortfall, then we have to pay for the operation from external funds. Summing payments over many operations is the measure of complexity.

omp2711 S1 2006 Amortized Complexity Example 4 Example: Extendable Arrays 6.1.5 Think of a queue implemented as an array. We have an array A of size N. If we fill it up and need more space we create an array B of size 2 N. Then we copy the elements of A into the first half of B. Copying N elements costs N dollars. If we start with an array of size 1, how do we analyse the performance of pushes? An accounting function φ is updated as follows. Let T 1 be the state of a newly doubled array, only the first half of which is filled. T 2 is the next state in which the overflow element is inserted into the first position of the second half. We charge 3 dollars for this insertion, paying 1 dollar for the cost of doing it, and save 2 dollars. Formally, φ(t 2 ) = φ(t 1 ) + 2. This is done for every push into the new second half.

omp2711 S1 2006 Amortized Complexity Example 5 A B C D E F G H First doubling filled copy A B C D E F G H I Second doubling due to overflow amount "deposited" into account Operations: Push charge 3 per push. Cost of push = 1. Excess 2 is deposited into account. Double array charge N for copying N elements into first half of doubled array. Use account to to pay for this we prove there is always enough. Figure 1: Account updating for push ops

omp2711 S1 2006 Amortized Complexity Example 6 Amortized complexity of N pushes is O(N) Overflow occurs when an array A has reached size 2 i for i 0. To copy its elements into the first half of a new array B of size 2 i+1 costs 2 i dollars. But from the previous round of insertions into the second half of array A, we have deposited 2 dollars into the account function for each such insertion. So the total amount deposited is 2 2 i 1 = 2 i dollars. Hence we have enough to pay for the copying. Therefore, it suffices to charge exactly 3 dollars for each insertion, i.e. this is an O(1) operation. Hence for N insertions the amortized complexity is O(N).

omp2711 S1 2006 Amortized Complexity Example 7 Comments on the Textbook Explanations I The text slides on amortized complexity for splaying are very high level outlines. Here are a few comments on the details in the textbook explanation. The account for a state (tree) is distributed across subaccounts for nodes, the amount of dollars deposited in each node is equal to its rank. In splaying a node x to a new position denoted by x you will notice that some nodes have their account increased and others have theirs decreased, but most are not changed.

omp2711 S1 2006 Amortized Complexity Example 8 Comments on the Textbook Explanations II So, if there is a net positive change, we the affected nodes can donate dollars to pay for the zig-zig or zig-zag (2 dollars each), or a zig (1 dollar). If negative, then we pay the difference. The invariant mentioned means this: each node before and after splaying can maintain an account (may be less or more than its old account) according to its new rank. But this is only possible because we pay to make up any shortfall. The text goes on to show that this payment is bounded by O(log n) dollars for an arbitrary splay.