DS-chapter11(Amoritized Analysis)

DS-chapter11(Amoritized Analysis) -...

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

View Full Document Right Arrow Icon
CHAPTER 11 Amortized Analysis Splay tree vs. AVL tree; skew heap vs. leftist heap Target : Any M consecutive operations take at most O( M log N ) time. -- Amortized time bound worst-case bound amortized bound average-case bound
Background image of page 1

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

View Full DocumentRight Arrow Icon
§2 Binomial Queues Claim A binomial queue of N elements can be built by N successive insertions in O(N) time. The worst case time for each insertion is ? O ( log N ) Proof 1: B 0 /*step = 1 */ B 1 /*step = 1, link = 1 */ B 1 B 0 /*step = 1*/ B 2 /*step = 1, link = 2 */ B 2 B 0 /*step = 1*/ B 2 B 1 /*step = 1, link = 1*/ B 2 B 1 B 0 /*step = 1*/ B 3 /*step = 1, link = 3*/ B 3 B 0 /*step = 1*/ … … … Total steps = N Total links = ) ( ...) 16 1 3 8 1 2 4 1 ( N O N = + × + × + +1 +0 +1 –1 +1 –2 Expensive insertions remove trees, while cheap ones create trees.
Background image of page 2
Proof 2: §2 Binomial Queues An insertion that costs c units results in a net increase of 2 c trees in the forest. C i ::= cost of the i th insertion T i ::= number of trees after the i th insertion ( T 0 = 0) C i + ( T i T i -1 ) = 2 for all i = 1, 2, …, N Add all these equations up
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: N T T C N N i i 2 1 =-+ = ) ( 2 2 1 N O N T N C N N i i = -= = T worst = O (log N ), but T amortized = 2 2 Binomial Queues T actual + Potential = T amortized Savings Account If an operation uses less than its allotted time, the unused time is saved in the form of a higher potential , for use later on by more expensive operations. In the case of the BuildBinomialQueue routine, the potential function can be taken as the number of trees . Note: While T actual varies from operation to operation, T amortized is stable. Note: While T actual varies from operation to operation, T amortized is stable . In general, a good potential function should Always assume its minimum at the start of the sequence (e.g. start from 0 and is always nonnegative). Cancel a term in the actual time....
View Full Document

Page1 / 4

DS-chapter11(Amoritized Analysis) -...

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

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