0% found this document useful (0 votes)
8 views16 pages

Advantages and Disadvantages of Randomized Algorithms

Uploaded by

ssmukherjee2013
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views16 pages

Advantages and Disadvantages of Randomized Algorithms

Uploaded by

ssmukherjee2013
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Randomized

Algorithms
Randomization
• Randomized Algorithms special kind of algorithm,
making random choices during execution
• Such choices help in breaking symmetry in input
and applying different logic for repeated
executions
• For many applications, Randomized Algorithms
are easier to implement and more efficient than
Deterministic Algorithms
• May sometimes lead to incorrect results, but with a
very small probability

2
Deterministic Algorithm

Algorithm
Input Output

• Algorithms takes an input and produces an


output, based in specific logic
• Correctness of the algorithm can be verified
• Achieves identical output for the same input,
through every re-run

3
Randomized Algorithm
Algorithm
Input Output

Random Bits

• Algorithms takes additional input, random bits


• Output depends upon both input and random
bits
• Will not provide identical output for the same
input if run multiple times

4
Performance Impact
• Some inputs may cause ‘worst-case’ performance in
Deterministic algorithms
• Randomized algorithm changes execution path
using random bit input
• Any given input resulting in ‘worst-case’
performance highly unlikely
• Randomization improves execution time in most
cases
• Worst case performance is possible, but in very rare
occasions
5
Advantages & Disadvantages
• Advantages:
– Can be simpler to implement
– Running time better than Deterministic
– In some cases, Deterministic Algorithm may
not exist

• Disadvantages:
– Randomness is a resource
– Correctness is not always guaranteed
– Fast running time is also not always possible
6
Types of Algorithm
• Las Vegas Algorithms:
– Correctness is guaranteed
– Running time may vary
– Probability of worst case running time is low

• Monte Carlo Algorithms:


– Running time is fixed
– Output may not always be correct
– Probability of incorrect output is low

7
Quick Sort Algorithm
Quicksort(list, first, last)

Begin

If first < last then

Set p := Partition(list, first, last)

// p: pivot location, between first & last

Quicksort(list, first, p-1) // L-Part

Quicksort(list, p+1, last) // R-Part

End if

End

8
Quick Sort Analysis
• Position of pivot determines the running time of
the algorithm
• Pivot position chosen Deterministically as part
of design, hence does not change during
execution
• If the pivot is positioned at the smallest/largest
element of the list, execution time is impacted
• Worst case running time is O(n2)

9
Randomized Quick Sort
Quicksort(list, first, last)

Begin

If first < last then

Randomly choose pivot location, p, between first &


last

Partition(list, p, first, last)

Quicksort(list, first, p-1) // L-Part

Quicksort(list, p+1, last) // R-Part

End if

End

10
Randomized Quick Sort Analysis
• Position of pivot chosen randomly for every
run of quick sort
• Changes in pivot position reduces probability
of always choosing same position elements as
pivot
• Execution path is thus randomized
• Estimated complexity: O(n log n)
• Complexity can still be O(n2) in worst case, but
with very, very low probability

11
Polynomial Testing
• How to determine if two given polynomials
of x, F(x) & G(x) are equal?
• Deterministic Algorithm
– Convert two polynomials in standard format
– Check whether they are same

– Always correct
– Complexity: Θ(n2), where n is the degree of
polynomial

12
Polynomial Testing
• Probabilistic Algorithm
– Choose r, from a set of 100n possible values
– Evaluate F(r) and G(r)
– If F(r) = G(r), then F(x) is same as G(x)

– Complexity: Θ(n)
– Probability of incorrect output <= 1/100
– Error can be reduced through repeated
execution, e.g., use two numbers, r1 and r2,
check if F(r1) = G(r1) and F(r2) = G(r2)
13
Comparison
• Quick Sort:
– Las Vegas algorithm
– Always gives correct result
– Running time may vary

• Polynomial Testing:
– Monte Carlo algorithm
– Running time is fixed
– Result not always correct, though correctness
may be ‘boosted’ by repeated execution
14
Summary
• Randomization usually leads to quite simple
algorithms to design & implement
• Sometimes, Randomization Algorithms are de-
randomized to get deterministic algorithms
• Many complexity classes have been defined for
Randomized Algorithms, similar to P, NP for
deterministic algorithms
• In some cases, randomization make it easier to
solve problems
• Randomization is a resource (like space/time),
truly random inputs are very expensive to obtain
15
The End

Common questions

Powered by AI

Las Vegas algorithms, such as Quick Sort, always produce a correct result, although their running time may vary depending on how the random choices affect execution . On the other hand, Monte Carlo algorithms, like the probabilistic algorithm for polynomial testing, have fixed running times but can result in incorrect outputs, although the error probability can be minimized with repeated runs .

In the probabilistic polynomial testing algorithm, the steps involve choosing a random number r from a set of 100n possible values, evaluating F(r) and G(r), and checking if they are equal. To reduce error probability, the test can be repeated with different random values r, such as r1 and r2, verifying equality at multiple points to minimize the likelihood of coincidental matches and confirm polynomial equivalence more robustly .

Randomization acts as a resource in algorithm design by providing the means to make flexible decisions that alter the execution path, thus improving efficiency in most cases. However, the use of randomization introduces the need to consider the availability and cost of generating random inputs. The implications include designing systems with reliable sources of randomness and understanding that access to quality random data is analogous to other resources like time and space .

The main advantages of randomized algorithms include simplicity in implementation, improved running time compared to deterministic algorithms in many cases, and the existence of solutions where deterministic algorithms might not exist. However, disadvantages include randomness being a resource that can be expensive to obtain, non-guaranteed correctness of results for every execution, and running time not always being fast .

Some randomized algorithms are de-randomized to create deterministic algorithms that eliminate the need for random inputs and ensure consistent correctness. The benefit of de-randomization includes avoiding the computational costs and difficulties associated with obtaining truly random inputs, as well as providing guaranteed correct results without relying on probabilities .

In quicksort, the position of the pivot heavily influences the running time. If the pivot is at an extreme (smallest or largest element), the algorithm degrades to a worst-case time complexity of O(n^2). Randomizing the pivot position ameliorates this by preventing such consistent extreme placements and by spreading the elements more evenly across recursive calls, thus typically achieving an average-case time complexity of O(n log n).

The probabilistic algorithm for polynomial testing differs from the deterministic one by evaluating the polynomials at a randomly chosen point r from a set of 100n possible values, checking if F(r) = G(r). It operates with complexity Θ(n) and a small error probability, which can be further reduced by repeated trials. Conversely, the deterministic algorithm converts polynomials to a standard format for comparison, ensuring correctness with complexity Θ(n^2).

Randomization affects the execution path of algorithms by allowing them to make different decisions during execution, potentially avoiding the ‘worst-case’ pathways that deterministic algorithms might encounter for certain inputs. This leads to improved execution times in most cases, as the probability of hitting worst-case performance is significantly lower .

The estimated complexity of randomized quicksort is O(n log n), which compares favorably to its worst-case scenario of O(n^2). The worst-case scenario is less likely because randomizing the pivot selection decreases the probability of encountering repeated extreme (smallest or largest) elements as pivots in successive recursive calls, thus reducing the chances of poor partitioning that leads to O(n^2) complexity .

The randomized quicksort algorithm reduces the probability of worst-case time complexity by choosing the pivot position randomly, which decreases the likelihood of consistently selecting the smallest or largest element as the pivot. This randomization of the pivot position thereby minimizes the probability of encountering the worst-case O(n^2) scenario and leads to an expected average time complexity of O(n log n).

You might also like