Randomized “Algorithms”
E N D
Presentation Transcript
Randomized “Algorithms” Monte Carlo and Las Vegas Technuques
Randomized • Monte Carlo • Might give an incorrect answer (approximate) but always give an answer • Las Vegas • Might never give an answer (quit or run forever) • Each uses some randomized technique to attack a problem
Monte Carlo Integration float area(function f, float a, float b, float fMax, int n) { float x, y; int hits=0, trial; for (trial=0; trial<n; trial++) { x = a+random(b-a); y = random(fMax); if (f(x)>=y) hits++; } return((b-a)*fMax*hits/n); }
Las Vegas and Ethernet bool success = false; while (!success) { status = message.send(); success = status == TRANSMITTED; if (!success) wait a bit; }
Las Vegas Dining Philosophers • Discussed in class Monte Carlo Illumination • Discussed in class
References • Some material from the textbook: Data Structures and Algorithm Analysis in Java (Second Edition) by Mark Allen Weiss • Additional images: www.wikipedia.com