Lec23b_AmortizedAnalysis_DisjointSets

Lec23b_AmortizedAnalysis_DisjointSets - Amortized Analysis...

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

View Full Document Right Arrow Icon
Amortized Analysis The average cost of a sequence of n operations on a given Data Structure. Aggregate Analysis Accounting Method Potential Method
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
Applications of amortized analysis Vectors/ tables Disjoint sets Priority queues Heaps, Binomial heaps, Fibonacci heaps Hashing Reducing the load factor by doubling
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Aggregate analysis n operations take T( n ) time Amortized cost of an operation is T( n )/ n
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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 .
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

Lec23b_AmortizedAnalysis_DisjointSets - Amortized Analysis...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online