Uploaded by Moon Light

Notes

advertisement
11/21/19 Notes by Jae
random number generation (RNG)
Generating random numbers 3
Randomization +
pseudo random number generation (PRNG)
Using random numbers
Birthday Paradox
;
~25 people in room, prob > < that 2 or more people will share the same birthday
Sources
1.
2.
3.
4.
5.
6.
ask human
system clock least significant digits
last four digits for phone, SSN
random.org “at morphemic noise” (interferences)
books listing random numbers
transcendental numbers
Old Sources
•
flip coin
•
roll dice
Applications
•
encryption
•
video gaming
•
lottery tickets/cosmos
UUID = Universally Unique Identifier
GUID = Globally Unique Identifier
Linear congruential generator multiplier: π‘₯@A; = (π‘Žπ‘₯@ + 𝑏) π‘šπ‘œπ‘‘ π‘š
Random permutation: 1, 2, 3, … , 𝑛
for i in range (n)
get random number between i and n-1
r = randInt(0, n-1-i) + i
swap(array, i, r)
Las Vegas Algorithms
Randomized algorithms that always get the correct answer time is random
1.
2.
3.
bogosort:
finds random permutation and checks if sorted
quicksort/quickselect
randomized pivot
rabin’s closest point
Monte Carb Algorithms
Time is constrained, but the “answer” given is not always correct
Ex.
Estimate 𝝅
x = Math.random( )
y = Math.random( )
1
some points will fall in circle (p)
some points will fall outside circle (100 – p)
1 <
πœ‹ Y2Z
𝐴OPQORS
π‘π‘œπ‘–π‘›π‘‘π‘  𝑖𝑛 π‘‘β„Žπ‘’ π‘π‘–π‘Ÿπ‘π‘™π‘’
=
=
⇒πœ‹=
𝐴TUVWQS
1
π‘‘π‘œπ‘‘π‘Žπ‘™ π‘›π‘’π‘šπ‘π‘’π‘Ÿ π‘œπ‘“ π‘π‘œπ‘–π‘›π‘‘π‘ 
𝑝
1
100 Y Z
2
<
=
𝑝
25
isPrime?
Prime = divisible only by 1 and itself
1.
2.
3.
4.
divide 𝑛 vy every number 2 up to 𝑛 − 1 if any divide evenly, then composite otherwise it is prime
stop searching at √𝑛
sieve of Eratosthenes filter out by all multiples of 2, 3, 5, … , √𝑛, what’s left is prime
Fermar’s Little Theorem
(randomized approach)
(π‘Ž@k; ≡ 1) π‘šπ‘œπ‘‘ 𝑛 ⇒ (π‘Ž@ ≡ π‘Ž) π‘šπ‘œπ‘‘ 𝑛 𝑖𝑓 𝑛 𝑖𝑠 π‘π‘Ÿπ‘–π‘šπ‘’ ∀ π‘Žπ‘™π‘™ 1 < π‘Ž < 𝑛
Select π‘˜ values of π‘Ž (π‘Ž; , π‘Ž< , π‘Žp , … , π‘Ž@ ) and see if π‘ŽP@k; ≡ 1 π‘šπ‘œπ‘‘ 𝑛?
If any π‘ŽP fails (π‘ŽP@k; ! = 1) then composite (not prime)
If none fail, then probably prime
Random Binary Search 𝑂(log 𝑛)
Harmonic Numbers Series 𝑂(log 𝑛)
Karger’s Min-Cut Algorithm
11/25/19 Notes by Jae
Approximation Algorithms
Approach to solving “intractable” — cannot be solved deterministically in polynomial time
Approximation Scheme
Way of asserting how close the approximation will be to the optimal solution
1. Absolute error bound
|𝐢 ∗ (π‘₯) − 𝐢(π‘₯)| ≤ πœ€ (π‘₯) ← functional of input size (more tolerant of larger error for larger problem size)
↑
↑
↑
Optimal
2.
3.
Computed error
by approx. alg
Ratio error bound
𝐢 ∗ (π‘₯) 𝐢(π‘₯)
max |
,
} ≤ πœ€(π‘₯)
𝐢(π‘₯) 𝐢 ∗ (π‘₯)
for minimization problem, 𝐢 ∗ (π‘₯) ≤ 𝐢(π‘₯)
maximization problem, 𝐢 ∗ (π‘₯) ≥ 𝐢(π‘₯)
Relative error bound
Download