3.1.7 · HinglishComplexity Analysis

Master theorem — solving recurrences T(n) = aT(n - b) + f(n)

1,734 words8 min readRead in English

3.1.7 · Coding › Complexity Analysis


Symbols ka matlab (KYA HAI)

Number leaves ka total cost hai. Sab kuch tumhare combine-cost ko isse compare karne par depend karta hai.


Scratch se derive karo (KAISE — kabhi bhi formula par andha bharosa mat karo)

Recursion ko ek tree mein unroll karo.

  • Level 0 (root): 1 node, kaam .
  • Level 1: nodes, har ek ka kaam → total .
  • Level : nodes, har ek ki size , kaam .
  • Last level: size tab 1 hoti hai jab .

Ab leaves gino. Leaves ki sankhya hai: Kyun? Use karo . Toh leaf cost .

Sum essentially ek geometric series hai jo ko se compare karta hai:

  1. Agar chhoti ho (): series neeche ki taraf grow karti hai, leaves dominate karti hain → .
  2. Agar equal ho (): har level ka cost lagbhag same hota hai, aur levels hain → se multiply karo.
  3. Agar badi ho (): root dominate karta hai → (ek regularity check chahiye taaki series actually root par converge kare).

Teeno cases (woh 20% jo tumhe memorize karna hi hai)

Figure — Master theorem — solving recurrences T(n) = aT(n - b) + f(n)

Forecast-then-Verify worked examples


YEH KAB TOOT-TA HAI (apni galtiyon ko steel-man karo)


Quick decision recipe (80/20)

  1. aur leaf cost compute karo.
  2. Polynomially chhota → Case 1 → answer .
  3. Equal (upto tak) → Case 2 → answer .
  4. Polynomially bada + regularity → Case 3 → answer .
  5. Cases ke beech sirf ek log gap ho → basic Master nahi; extended Case 2 use karo.

Recall Feynman: ek 12-saal ke bachche ko samjhao (click to reveal)

Socho ek kaam hai jo tum dosto mein baant dete ho. Har round mein tum har dost ko ek chhota kaam dete ho, lekin saath mein khud bhi kuch sorting ka kaam karte ho. Do costs ladte hain: neeche bahut saare tiny chores ka giant pile vs upar tumhara bada sorting kaam. Master Theorem bas ek referee hai: dekho kitni tezi se chores multiply ho rahe hain () versus kitni tezi se shrink ho rahe hain (). Agar tiny chores tumhe daba dein, answer leaf cost hai. Agar tumhari apni sorting tumhe daba de, answer top cost hai. Agar tie ho, har floor par same cost pay karte ho, toh floors ki sankhya () se multiply karo.


Connections

  • Recursion Trees — woh visual derivation jo Master Theorem summarize karta hai.
  • Akra–Bazzi method — unequal subproblems / non-constant splits ke liye generalization.
  • Big-O, Big-Omega, Big-Theta — asymptotic comparison machinery.
  • Merge Sort, Karatsuba Multiplication, Binary Search — direct applications.
  • Geometric Series — kyun teeno cases exist karte hain (increasing/flat/decreasing series).

Flashcards

Master Theorem recurrence ko define karne wale teeno quantities kya hain?
= subproblems ki sankhya, = shrink factor (), = recursion ke bahar kaam (split+combine).
Critical exponent kya hai aur kya represent karta hai?
; recursion tree ki leaves ka total cost hai.
Master Theorem ka Case 1 batao.
Agar , toh (leaves jeette hain).
Case 2 (extended) batao.
Agar , toh .
Case 3 aur uski extra condition batao.
Agar AUR kisi ke liye, toh .
Case 2 mein se kyun multiply karte hain?
Har level ka cost same hota hai () aur levels hote hain, toh total = level cost × levels ki sankhya.
solve karo.
, → Case 2 → .
solve karo.
, → Case 2 → (binary search).
Basic Master Theorem kyun solve nahi kar sakta?
, se sirf ek log factor se zyada hai, polynomial factor se nahi — gap mein aata hai; extended Case 2 deta hai .
Leaves ki sankhya kyun hai?
.
Master Theorem kab apply NAHI hota?
Jab non-constant hon; unequal subproblem sizes (e.g. ); non-polynomial gaps; negative .

Concept Map

split into

shrink by

combine cost

defines

defines

gives leaf cost

unroll into

geometric series compares

f smaller, leaves win

tie times log^k

f bigger plus regularity

is the baseline for

is the f in

T of n = a T of n/b + f of n

a subproblems

factor b

f of n

critical exponent log_b a

n^log_b a

recursion tree sum over levels

f vs n^log_b a

Case 1: Theta n^log_b a

Case 2: Theta n^log_b a log^k+1 n

Case 3: Theta f of n