x i = indicator random variable of the event that i-th person gets his hat back. e[x i ]=1/20 x=x 1...
Post on 22-Dec-2015
221 views
TRANSCRIPT
![Page 1: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/1.jpg)
Xi = indicator random variable of the event that i-th person gets his hat back.
E[Xi]=1/20X=X1+…+X20
E[X] = E[X1] +…+ E[X
20] = 1
![Page 2: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/2.jpg)
derangement = permutation with no fixed points
n! / e permutations with 1 fixed point
number =
![Page 3: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/3.jpg)
derangement = permutation with no fixed points
n! / e permutations with 1 fixed point
number =
n (n-1)! / e
n (n-1)! / e
n!0.3678 0.368
![Page 4: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/4.jpg)
![Page 5: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/5.jpg)
Claim: Alice wins only on HHH game.
1/8 - Alice wins, gets $67/8 - Alice loses, pays $1= gets -$1
Alice’s expected payoff: (1/8)* 6 + (7/8) * (-1) = - 1/8
Bob has the advantage.
![Page 6: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/6.jpg)
![Page 7: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/7.jpg)
Heap
MIN-HEAP-INSERT O(log k)HEAP-EXTRACT-MIN O(log k)
…
P1
Pk
![Page 8: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/8.jpg)
We will find the array Ai whose first element e is the smallest, output e to B, remove e from Ai, and repeat. We will use a heap H as follows: we find e using Heap-Extract-Min procedure and then add the next element from Ai to Husing Min-Heap-Insert procedure. We make n calls to Min-Heap-Insert and n calls to Heap-Extract-Min. Hencethe running time is O(n.log k). To simplify the exposition we add at the end of each array. for i from 1 to k do
Pi 1; Max-Heap-Insert( H,[Ai[1],i] );for j from 1 to n do [e,i] Heap-Extract-Max (H); Pi Pi + 1; Max-Heap-Insert( H, [Ai [Pi],i] ); add e to B
![Page 9: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/9.jpg)
![Page 10: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/10.jpg)
<
![Page 11: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/11.jpg)
<
LA1,RAn,LB1,RBnwhile LA<R
A do
MA (LA + RA)/2 MB (L + R)/2 if A[MA]<B[M] then LA M+ 1, R M- 1
else RA M, L M
output smaller of A[LA],B[LB]
![Page 12: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/12.jpg)
Randomized algorithm for “median”
L R
<x =x >x
for random x
2) recurse on the appropriate part
1)
SELECT k-th element
![Page 13: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/13.jpg)
Quick-sort
L R
<x =x >x
for random x
2) recurse on both parts
1)
PA
RTIT
ION
![Page 14: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/14.jpg)
Quick-sort
R-QUICK-SORT (A, l, r) x random element of A[l,r]; q PARTITION(A,x,l,r); R-QUICK-SORT(A,l,q-1); R-QUICK-SORT(A,q+1,r);
![Page 15: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/15.jpg)
Quick-sort
R-QUICK-SORT (A, l, r) x random element of A[l,r]; q PARTITION(A,x,l,r); R-QUICK-SORT(A,l,q-1); R-QUICK-SORT(A,q+1,r);
How many times is R-QUICK-SORT called?
![Page 16: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/16.jpg)
Quick-sortR-QUICK-SORT (A, l, r) x random element of A[l,r]; q PARTITION(A,x,l,r); R-QUICK-SORT(A,l,q-1); R-QUICK-SORT(A,q+1,r);
Time spent in PARTITION?
![Page 17: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/17.jpg)
Quick-sortR-QUICK-SORT (A, l, r) x random element of A[l,r]; q PARTITION(A,x,l,r); R-QUICK-SORT(A,l,q-1); R-QUICK-SORT(A,q+1,r);
Time spent in PARTITION?
compare x with all elements in A[l,r]
we will count the number of comparisons
![Page 18: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/18.jpg)
Quick-sortR-QUICK-SORT (A, l, r) x random element of A[l,r]; q PARTITION(A,x,l,r); R-QUICK-SORT(A,l,q-1); R-QUICK-SORT(A,q+1,r);
Time spent in PARTITION?
Let the elements of A after sorting be b1 < b2 < … < bn
Let Xi,j be the indicator random variable for the event bi is compared to bj.
![Page 19: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/19.jpg)
Quick-sortTime spent in PARTITION?
Let the elements of A after sorting be b1 < b2 < … < bn
Let Xi,j be the indicator random variable for the event bi is compared to bj.
What is the probability that bi and bj arecompared in the first round ?
![Page 20: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/20.jpg)
Quick-sortTime spent in PARTITION?
Let the elements of A after sorting be b1 < b2 < … < bn
Let Xi,j be the indicator random variable for the event bi is compared to bj.
What is the probability that bi and bj arecompared in the first round ?
2/n (the pivot has to be bi or bj)
![Page 21: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/21.jpg)
Quick-sortTime spent in PARTITION?
What is the probability that bi and bj arecompared ?
2/(j-i+1)
Let bk be the first pivot such that ik j.
bi, bj get compared k=i or k=j
k is uniformly random in {i,…,j}
![Page 22: X i = indicator random variable of the event that i-th person gets his hat back. E[X i ]=1/20 X=X 1 +…+X 20 E[X] = E[X 1 ] +…+ E[X 20 ] = 1](https://reader034.vdocuments.us/reader034/viewer/2022052603/56649d785503460f94a5b335/html5/thumbnails/22.jpg)
Quick-sortTime spent in PARTITION?
What is the probability that bi and bj arecompared ?
2/(j-i+1)
E[Xi,j] = 2/(j-i+1)
X= Xi,j1i<j n
E[X]=n = O(n ln n)2
j-i+11i<j n k=2
n2
k