Presentation is loading. Please wait.

Presentation is loading. Please wait.

Randomized Algorithms

Similar presentations


Presentation on theme: "Randomized Algorithms"— Presentation transcript:

1 Randomized Algorithms

2 Deterministic Vs Randomized Algorithms
Deterministic Algorithms Randomized Algorithms Algorithm Algorithm I/P O/P I/P O/P Random Bits

3 What are Randomized Algorithms?
Algorithms whose behavior depends on: Input(s) A sequence of random bits (these random bits lead to: random steps, choices, decisions,…,etc. during the running of the algorithm) Can be faster and simpler than a deterministic algorithm Two types: Las Vegas Mont Carlo

4 Las Vegas or Mont Carlo Always returns Correct answer
Running time Fast with a High Probability Always runs Fast Returns Correct answer with a High Probability

5 Example 1 Input: array of n chars, half ‘a’s, half ‘b’s
Problem: Find location of any ‘a’ Deterministic Approach: Search One by One  worst case: O(n/2) Randomized Approach: Check entries at random until ‘a’ is found Probability of finding ‘a’ right away = 0.5 Probability of missing ‘a’ k times in a row = 0.5k Which type of algorithm is it?

6 Example 2: Microchip Test
We want to know if the manufacturer tested a batch of chips For an untested batch, P(bad) = 0.1 Deterministic Algorithm: test them all  O(n) Randomized Algorithm: test chips at random

7 Example 2: Microchip Test
Question to ask: “Has this batch NOT been tested?” TRUE – if random algorithm finds a bad chip UNKNOWN – if algorithm finds a good chip After k chips, algorithm concludes FALSE, therefore the batch is GOOD. Probability a good chip came from untested batch = 0.9 Probability “good” batch is actually bad = 0.9k

8 Example 2: Microchip Test
0.9k = probability a bad batch is being tested and we keep finding the good chips, k times in a row For k = 66, chances of a bad batch slipping through is less than 1 in a 1000 => small Running time = O(k), independent of n, determined by k set by programmer => fast Monte Carlo: running time fast, correctness probability high

9 Example 3: Min-Cut Input: A connected, undirected graph G = (V,E)
Output: A min-cut, i.e. smallest set of edges to remove that splits graph into two Possible approaches: Try them all – exponential since there are 2|E| subsets of edges Modified max-flow algorithm for all s-t pairs – O(|V|3) x O(|V|2) pairs of vertices = O(|V|5)

10 Example 3: Min-Cut Randomized approach: O((nlogn)2)
Same idea as chip test: one time through the algorithm yields a relatively low probability of success repeat algorithm to reduce probability of repeated failure until satisfied with probability of success Will only show algorithm and that it works with a certain probability of success

11 Example 3: Min-Cut Algorithm:
Randomly select an edge Merge its end-points Repeat until two vertices remain How do we know this algorithm is reliable?

12 Pr[min-cut edge] £ c/(nc/2)
Analysis I Min-cut is small---few edges Suppose graph has min-cut c Then minimum degree at least c Thus at least nc/2 edges Random edge is probably safe Pr[min-cut edge] £ c/(nc/2) = 2/n 15

13 Analysis II Algorithm succeeds if never accidentally contracts min-cut edge Contracts #vertices from n down to 2 When k vertices, chance of error is 2/k thus, chance of being right is 1-2/k Pr[always right] is product of probabilities of being right each time 16

14 Analysis III …not too good! 17

15 Repetition Repetition amplifies success probability
basic failure probability 1 - 2/n2 so repeat 7n2 times 18


Download ppt "Randomized Algorithms"

Similar presentations


Ads by Google