Probabilistic algorithms Flashcards
Probabilistic quick sort algorithm (idea)
Pick a random index as the pivot point of the algorithm. Recursively do this until the sorting is done.
Probabilistic quick sort algorithm (run time)
We got a runtime that in the bad case in avarage is O(nlogn) where the bad cases are negligible. Inn the regular sort the bad case of O(n^2) is not negligible.
Random min cut (idea)
Choose a random edge, and combine the two vertices into one. Do this until you are left with only two nodes. (The graph will include multiple edges going from one node to the other, that will be the min cut)
Random min cut (accuracy)
In one run the algorithm has a (2/(n^2)) chance of getting it right. if you run it ((n^2)/2) times, it has a a chance of being wrong that is smaller than 1/e .
Las Vegas algorithm
A probabilistic algorithm, that is never wrong and the run time is calculated by the expectation (תוחלת)
Monte Carli algorithm
A probabilistic algorithm that might be wrong. You can mitigate this by running multiple times. The run time isn’t random.
Matrix multiplication determinition (idea and run time)
Choose a random 1d vector x and multiply both sides ABx=Cx. If ABx≠Cx the for sure AB≠C. But if ABx=Cx then there is a 50% chance that AB=C. Run this multiple times each time choosing a new random vector. Runtime is O(n^2)
AKS algorithm
Ann algorithm for accurately determining if a number is prime in O(n^6)
Fermat’s Little Theorem
If p is a prime number, for any integer a: a^p = a%p
The Miller Rabin primality test
Given a number p, pick a random integer a, and test if a^p = a%p. If not then p is for sure not prime else it might be. do this k times to control the mistake probability. There is a 4^(-k) probability for false positive. O(n^3) time (n number of digits)