Sie sind auf Seite 1von 6

Randomized algorithm

A randomized algorithm is an algorithm which employs a degree of randomness as part of its logic the algorithm typically uses uniformly random bits as an auxiliary Input to guide its behavior, in the average case over all possible choices of random bits. Formally, the algorithms performance will be a random variable determined by the random bits; this either the running time or the output or (both) are random variables. Based on this factor of random running time or output there are two forms of randomized algorithm: 1. Las Vegas Algorithm : Algorithms that use the random input to reduce the expected running time or memory usage, but always terminate with a correct results in a bounded amount of time 2. Monte Carlo Algorithm: Probabilistic algorithms, which, depending on the random input, have a chance of producing an incorrect result or fail to produce a result either by signaling a failure or failing to terminate In common practice, randomized algorithms are approximated using a pseudorandom number generator in place of a true source of random bits; Such an implementation may deviate from the expected behavior

APPLICATIONS

Quicksort It is a commonly used sorting algorithm in which randomness can be useful. Any deterministic version of this algorithm O (n^2) time to sort n numbers for some welldefined class of degenerate inputs (such as already sorted array), with the specific class of inputs that generate this behavior defined by the protocol for pivot selection. However, if the algorithm selects pivot elements uniformly at random, it has a provably high probability of finishing in O (n log n) time regardless of the characteristics of the input. Randomized Incremental constructions in geometry: In computational geometry, a standard like a convex hull is to randomly permute the input points and then insert them one by one into the existing structure. The randomization ensures that the expected number of changes to the structure caused by an insertion is small, and so the expected running time of the algorithm can be upper bounded. This technique is known as randomized incremental construction.

NEED OF RANDOMNESS
Based on the initial motivating example: given an exponentially long string of 2^k characters, half as and half bs, a random access machine requires at least 2^(k-1) lookups in the worst case to find the index of an a; if it is permitted to make random choices, it can solve

PAGE 1

this problem in an expected polynomial number of lookups. In communication complexity, the equality of two strings using log n bits of communication with a randomized protocol any deterministic protocol requires (n) bits.

Quicksort
The Basic version of quicksort algorithm was invented by C.A.R. Hoare in 1960 and formally introduced quicksort in 1962. It is used on the principle of DIVIDE and CONQUER algorithm. Quicksort is an algorithm of choice in many situations because it is not difficult to implement, it is a good general purpose sort and utilizes relatively fewer resources during execution.

Pros: It is in-place since it uses only a small auxiliary stack. It requires only n log(n) time to sort n items. It has an extremely short inner loop This algorithm has been subjected to a thorough mathematical analysis, a very precise statement can be made about performance issues.

PAGE 2

Cons: It is recursive. If recursion is not available, implementation is extremely complicated. It requires quadratic (i.e., n^2) time in the worst case. It is fragile i.e. a simple mistake in implementation can go unnoticed and cause it to perform badly

Performance and complexity:


Worst Case - O(n^2) Average Case O(n log n) Best Case O(n log n) (for simple partition) or O(n) (for three way partition and equal keys) Randomized Quick sort

Randomized Quicksort In the randomized version of Quick sort we impose a distribution on input. This does improve the worst case running time independent of input ordering. In this version we choose a random key for the pivot. Assume that procedure Random(a,b)returns a random integer in the range[a,b); there are b-a+1 integer in the range and procedure is equally likely to return one of them. The new partition procedure simply implemented the swap before actually partitioning.

PAGE 3

Like other randomized algorithm RANDOMIZED_QUICKSORT has the property that no particular input elicits its worst case behavior; The behavior of this algorithm only depends on the random number generator. Even intentionally we cannot produce a bad input for randomized quicksort unless we can predict what number the generator will produce next.

Complexity and Performance Average case [Expected running time] (n log(n)) Worst case ( )

PAGE 4

PAGE 5

Das könnte Ihnen auch gefallen