Docsity

Randomized Algorithm, Lecture notes of Design and Analysis of Algorithms

Partial preview of the text

Download Randomized Algorithm and more Lecture notes Design and Analysis of Algorithms in PDF only on Docsity!

An Introduction

Flip a coin

An algorithm which flip coins is called a randomized algorithm.

A randomized algorithm is faster.

Making good decisions could be expensive.

Consider a sorting procedure. Picking an element in the middle makes the procedure very efficient, but it is expensive (i.e. linear time) to find such an element.

5 9 13 11 8 6 7 10

5 6 7 8 9 13 11 10

Picking a random element will do.

 Avoid worst-case behavior: randomness can (probabilistically) guarantee average case behavior

 Efficient approximate solutions to intractable problems

 In many practical problems,we need to deal with HUGE input,and don’t even have time to read it once.But can we still do something useful?

 Randomized algorithms make random rather than deterministic decisions.

 The main advantage is that no input can reliably produce worst-case results because the algorithm runs differently each time.

 These algorithms are commonly used in situations where no exact and fast algorithm is known.

 Behavior can vary even on a fixed input.

 Minimum spanning trees

A linear time randomized algorithm, but no known linear time deterministic algorithm.

 Primality testing

A randomized polynomial time algorithm, but it takes thirty years to find a deterministic one.

 Volume estimation of a convex body

A randomized polynomial time approximation algorithm, but no known deterministic polynomial time approximation algorithm.

 Always gives the true answer.

 Running time is random.

 Running time is variable whose expectation is bounded(say by a polynomail).

 E.g. Randomized QuickSort Algorithm

 It may produce incorrect answer!

 We are able to bound its probability.

 By running it many times on independent random variables, we can make the failure probability arbitrarily small at the expense of running time.

E.g. Randomized Mincut Algorithm

Suppose A 1 < … < An.

We want Ai, such that i ≥ n/2.

It’s obvious that the best deterministic algorithm needs O(n) time to produce the answer.

n may be very large!

Suppose n is 100,000,000,000!

 Choose 100 of the numbers with equal probability.

 find the maximum among these numbers.

 Return the maximum.

 QUICKSORT

QuickSort is a simple and efficient approach to sorting:

 Select an element m from unsorted array c and divide the array into two subarrays: c small - elements smaller than m and c large - elements larger than m.

 Recursively sort the subarrays and combine them together in sorted array c sorted

 Runtime is based on our selection of m :

-A good selection will split c evenly such that | c small | = | c large |, then the runtime is O( n log n ).

-For a good selection, the recurrence relation is: T ( n ) = 2T ( n /2) + const · n

Time it takes to split the array into 2 parts where const is a positive constant

The time it takes to sort two smaller arrays of size n /

However, a poor selection will split c unevenly and in the worst case, all elements will be greater or less than m so that one subarray is full and the other is empty. In this case, the runtime is O( n^2 ).

For a poor selection, the recurrence relation is: T(n) = T(n-1) + const · n

The time it takes to sort one array containing n - elements

Time it takes to split the array into 2 parts where const is a positive constant