3.7.19 · D3 · HinglishAlgorithm Paradigms

Worked examplesRandomized algorithms — Las Vegas, Monte Carlo

4,166 words19 min read↑ Read in English

3.7.19 · D3 · Coding › Algorithm Paradigms › Randomized algorithms — Las Vegas, Monte Carlo

Yeh page parent topic ka drill floor hai. Hum har tarah ki situation cover karenge jo do algorithm classes throw kar sakti hain: perfect success, tiny success, ek repetition, kaafi repetitions, degenerate "impossible" cases (, ), error ki do directions, ek class ko doosri mein convert karna, aur ek real word problem. Har answer se pehle guess karo — forecast karna hi aadhi learning hai.

Yahan sab kuch parent note ke teen tools pe tikaa hai, jinhe hum neeche use karte waqt phir se earn karte hain: geometric expectation , exponential boosting , aur Markov's inequality. Agar koi symbol aisa aaye jo tumne pehle na dekha ho, ruko aur phir se padho — I promise to have built it first.


Scenario matrix

Kuch bhi solve karne se pehle, yeh poora map hai cases ka. Har worked example neeche tagged hai us cell se jise woh cover karta hai, taaki tum dekh sako ki kuch bhi skip nahi hua.

Cell Class Kya random hai Jo tricky part test ho raha hai
A Las Vegas running time typical success prob : expected trials
B Las Vegas running time degenerate (almost never works) aur (always works)
C Las Vegas running time expected work jab har trial ka cost ho, nahi
D Monte Carlo the answer one-sided error, single run
E Monte Carlo the answer one-sided boosting: kitne runs chahiye target ke liye
F Monte Carlo the answer two-sided error — kyun majority vote, last run nahi
G Conversion LV → MC via a time budget + Markov's inequality
H Conversion MC → LV via cheap verification
I Real-world mixed ek word problem jo tumhe class choose karne par majboor karta hai
J Exam twist ", " magic number, aur ek limiting sanity check

Har cell ko jo tool chahiye — is flow chart ko aise padho ki "har family of examples ek tool pull down karti hai":

geometric

multiply independent

vote

tail bound

Cells A B C and H

E of N equals 1 over p

Cells D E and J

error at most q to the k

Cell F

Chernoff majority

Cell G

Markov inequality

Chart ko node by node kaise padhen.

  • T1 ("E of N equals 1 over p") geometric expectation hai. Examples 1, 2, 3 (cells A, B, C) aur Example 8 (cell H) sab yahi lever kheenchte hain — trials count karo, ko success chance se divide karo.
  • T2 ("error at most q to the k") exponential boosting hai. Examples 4 aur 5 (cells D, E) aur Example 10 (cell J) iska use karte hain — per-run error ko khud se baar multiply karo.
  • T3 ("Chernoff majority") voting tool hai. Example 6 (cell F) iska use karta hai — jab koi single answer trustworthy nahi hoti, ballots count karo aur Chernoff Bounds guarantee pe lean karo.
  • T4 ("Markov inequality") tail bound hai. Example 7 (cell G) iska use karta hai — sirf mean use karke time budget overrun hone ka chance bound karo. Example 9 (cell I, real-world) tools mix karta hai taaki class choice force ho.

Deeper machinery hum link karte hain jahan woh rehti hai: Probability and Expectation, Markov's Inequality, Chernoff Bounds.


Building block figures

Do pictures hain jo har Las Vegas / Monte Carlo calculation carry karti hain. Inhe open rakhna.

Figure — Randomized algorithms — Las Vegas, Monte Carlo
Figure s01 — Do random worlds. Left panel: magenta curve hai ; horizontal axis success probability hai se tak, vertical axis expected trials hai. Jaise left ki taraf shrink hota hai, curve upar rocket karta hai (cell B ka blow-up). Violet dot mark karta hai trials. Right panel: curves hain (error after runs) log vertical axis par; magenta hai , violet hai , aur orange dashed line hai target . Dono curves dive karti hain kyunki hum se chhota number khud se multiply karte hain (cells D–E). Left = Las Vegas (time random), right = Monte Carlo (answer random).


Worked examples

Cell A — Las Vegas, typical success probability


Cell B — Las Vegas, degenerate aur


Cell C — Las Vegas, cost per trial


Cell D — Monte Carlo, one-sided error, single run


Cell E — Monte Carlo, one-sided boosting

Figure s02 — One-sided boosting bars. Horizontal axis rounds ka number hai ( se tak); vertical axis error bound hai log scale par. Har bar apne left wale bar ki height ka one-quarter hai — error har round mein ka factor drop karta hai. Orange dashed line target hai. Magenta bars () abhi bhi line se upar hain; violet bars () neeche hain. Round aur round ke beech crossover exact reason hai ki tight minimum kyun hai.


Cell F — Monte Carlo, two-sided error (voting kyun)


Cell G — Conversion: Las Vegas → Monte Carlo


Cell H — Conversion: Monte Carlo → Las Vegas


Cell I — Real-world word problem


Cell J — Exam twist: "" magic number & ek limiting check


Recall Quick self-test

One-sided MC test errs with per run; kitne runs ke liye error ho? ::: . Las Vegas retry with , cost per trial — expected work? ::: . Two-sided MC, , correct-prob , majority — kya single run se beat karta hai? ::: , haan. LV → MC via Markov: overrun ke liye budget? ::: , budget .

Related deep material: QuickSort, Quickselect, Min-Cut and Max-Flow, Amortized vs Expected Analysis, aur Hinglish companion 3.7.19 Randomized algorithms — Las Vegas, Monte Carlo (Hinglish).