Lec23b_AmortizedAnalysis_DisjointSets

# Lec23b_AmortizedAnalysis_DisjointSets - Amortized Analysis...

This preview shows pages 1–11. Sign up to view the full content.

Amortized Analysis The average cost of a sequence of n operations on a given Data Structure. Aggregate Analysis Accounting Method Potential Method

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Amortized Analysis Amortized analysis computes the average time required to perform a sequence of n operations on a data structure Often worst case analysis is not tight and the amortized cost of an operation is less than its worst case. Analogy (making coffee)
Applications of amortized analysis Vectors/ tables Disjoint sets Priority queues Heaps, Binomial heaps, Fibonacci heaps Hashing Reducing the load factor by doubling

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Difference between amortized and average cost To do averages we need to use probability For amortized analysis no such assumptions are needed We compute the average cost per operation for any mix of n operations
The Data Structure The data structure has a set of operations. A stack with push(), pop() and MultiPop(k). Often some operations may be slow while others are fast. push() and pop() are fast. MultiPop(k) may be slow. Sometime the time of a single operation can vary

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Methods Aggregate analysis - the total amount of time needed for the n operations is computed and divided by n Accounting - operations are assigned an amortized cost. Objects of the data structure are assigned a credit Potential – The prepaid work (money in the “bank”) is represented as “potential” energy that can be released to pay for future operations
Aggregate analysis n operations take T( n ) time Amortized cost of an operation is T( n )/ n

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Stack - aggregate analysis A stack with operations Push , Pop and Multipop . Multipop (S, k) while not empty (S) and k>0 do Pop(S); k:=k-1 end while
Stack - aggregate analysis Push and Pop are O(1) (to move 1 data element) Multipop is O( min ( s , k )) where s is the size of the stack and k the number of elements to pop. Assume a sequence of n Push , Pop and Multipop operations

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Stack - aggregate analysis Each object can be popped only once for each time it is pushed So the total number of times Pop can be called ( directly or from Multipop) is bound by the number of Pushes <= n .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 38

Lec23b_AmortizedAnalysis_DisjointSets - Amortized Analysis...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online