3.1.5 · HinglishComplexity Analysis

Amortized analysis — aggregate, accounting, potential methods

1,730 words8 min readRead in English

3.1.5 · Coding › Complexity Analysis


dhundhne ke teen methods hain. Sab same total bound dete hain; farq sirf accounting ke tarike mein hai.


1. Aggregate method — "bas sab jod lo"


2. Accounting (banker's) method — "pehle se pay karo aur credit bachao"


3. Potential method — "structure mein stored energy"

Figure — Amortized analysis — aggregate, accounting, potential methods

Recall Feynman: ek 12-saal ke bacche ko samjhao

Ek piggy bank imagine karo. Har baar jab tum ek chhota kaam karte ho, tum 3 coins daalte ho par kaam sirf 1 coin ka "effort" leta hai. Extra 2 coins pile up hote hain. Kabhi kabhi ek BAHUT BADA kaam aata hai (poora kamra saaf karna). Rone ki jagah, tum piggy bank tod dete ho — aur surprise, tumne exactly itne coins bachaye hain jo usse pay karne ke liye kafi hain! Toh chahe ek kaam bahut bada lagta tha, average par har kaam ne tumhe sirf 3 coins cost kiye. Yahi averaged-but-guaranteed price amortized cost hai, aur piggy bank potential function hai.


Flashcards

Amortized cost kis tarah ka average hai — inputs par ya sequence par guaranteed?
Kisi bhi sequence of operations par guaranteed worst-case; koi probability/randomness NAHI hai.
Aggregate method ek line mein
ops ka total cost seedha compute karo, phir amortized cost (har op ke liye same).
Dynamic array push amortized kyon hai jabki copies hain?
Copies geometrically rarely hoti hain; total copy work , toh total .
Accounting method validity condition
Total stored credit hamesha rehna chahiye (bank kabhi negative nahi jata).
Potential method ki master equation
(actual cost plus potential mein change).
Potential method valid upper bound kyon deta hai?
Telescoping: ; agar toh .
Ek achhe potential function ki do requirements
aur har ke liye.
Table doubling ke liye potential function
(n = #elements, s = capacity), per push deta hai.
Binary counter increment ki amortized cost
— $2 charge karo: $1 bit set karne ke liye, $1 us par store karo uske future flip ke liye pay karne ke liye.
Amortized vs average-case complexity ka farq
Amortized = ek sequence par deterministic guarantee; average-case = inputs ke random distribution par expectation.

Connections

  • Dynamic Arrays / Table Doubling — canonical amortized example.
  • Big-O, Big-Omega, Big-Theta — amortized bounds abhi bhi asymptotic notation mein express hote hain.
  • Disjoint Set Union (Union-Find) — path compression + union by rank potential ke zariye analyze kiya gaya.
  • Splay Trees amortized ek potential function ke zariye.
  • Fibonacci Heaps — decrease-key amortized marked nodes ke potential se.
  • Geometric Series — aggregate method ke peeche ka summation engine.

Concept Map

guarantees

differs from

reports

must satisfy

3 methods

3 methods

3 methods

computes

stores surplus as

example

example

copies form

yields

Amortized analysis

Worst-case avg per op

Average-case with randomness

Amortized cost c-hat

Sum c-hat >= Sum actual cost

Aggregate

Accounting banker

Potential

Total T of m over m

Credit >= 0 always

Dynamic array doubling

Geometric series < 2m

O(1) per push