Upload
huso3000
View
215
Download
0
Embed Size (px)
Citation preview
8/10/2019 Coupon Collector Problem
1/11
Coupon collectors problem
CS658
Po-Ching Liu
8/10/2019 Coupon Collector Problem
2/11
Question
A person trying to collect each of b differentcoupons must acquire approximately xrandomly obtained coupons in order tosucceed.
find x
8/10/2019 Coupon Collector Problem
3/11
Balls and bins
1st question:
If n identical balls are tossed randomly into b bins, then how many balls will fall in a given bin? Ans:
b
n
. bn
b1
n ballsnof numberexpected the
, b
1 is bingivenanyinlands balltosseday that probabilitthe
8/10/2019 Coupon Collector Problem
4/11
Second
Second question:Find the expected number of balls we need totoss (one ball for each toss) until a given bincontains a ball.The number of bins = b
Ans: E = b
8/10/2019 Coupon Collector Problem
5/11
proof p=pro(success) = 1/b= 1-q q=pro( without success)=1-1/b=1- p E[# of tosses until a given bin contains a ball]
b
b p p p
pqq
p
qqqqqqq
p E
pqqqqqqq
qqq
qqqqqqqqqq p
qqqqqq p
qqqpqqpqp p E
)1(
1111)
1
1)(
1
1(
)1)(1
1(
11
1) 1(
]
)qqq(1
) 1(
) 1( ) 1[(
]4 3 2 1[
4321
8/10/2019 Coupon Collector Problem
6/11
Third
the third question:Find the expected number of balls we need totoss (one ball for each toss) until every bincontains at least one ball?The number of bins = b
Ans: E = b(lnb+O(1))
8/10/2019 Coupon Collector Problem
7/11
proof
There are b stages The ith stage consists of the tosses after
the (i-1)th hit until the ith hit. how many balls do we have to toss in order to
move from the (i-1) th stage to the ith stage there are (i-1) bins that contain balls and
b-(i-1) empty bins.for each toss in the ith stage, the
probability of obtaining a hit is (b-i+1)/b .
8/10/2019 Coupon Collector Problem
8/11
proof
E[# of tosses in the ith stage]= E[total # of tosses in the 1 st to the bth stage]
= )11
21
21
111
(11 bbb
bibbb
i
constantc ln][ln1
1
11
1
)1
11
31
21
11
(
)11
21
21
111(
1111
1
cbc xdx xidx x
i
bb
bbb
bb
x
b
i
b
x
b
i
1ib
b
8/10/2019 Coupon Collector Problem
9/11
proof
))1((ln)(ln
)112121111(11Obbcbb
bbbbib bb
i
We find the two following questions are the same: Q:Find the expected number x of balls we need to toss (one
ball for each toss) until every bin contains at least one ball?The number of bins = b
Q: A person trying to collect each of b different couponsmust acquire approximately x randomly obtained couponsin order to succeed.
))O(bb(x 1ln
8/10/2019 Coupon Collector Problem
10/11
Code by java compile: javac CouponCollector.javaRun: java CouponCollector
public class CouponCollector { public static void main(String[] args) { int N = 50; // number of different card types boolean[] found = new boolean[N]; // found[i] = true ==> if card i has been collected , false ==> the new type of card int cardcnt = 0; // total number of cards collected int valcnt = 0; // number of distinct cards // repeatedly choose a random card and check whether it's a new one while (valcnt < N) { int val = (int) (Math.random() * N); // random card between 0 and N-1 cardcnt++; // we collected one more card ==>total number +1 if (!found[val]) valcnt++; // it's a new card type found[val] = true; // update found[] } // print the total number of cards collected System.out.println(cardcnt); } }
8/10/2019 Coupon Collector Problem
11/11
references
Thomas H. Cormen,Charles E. Leiserson,Ronald L. Rivest, Clifford Stein(1990),Introduction to Algorithms, The MIT Press,Cambridge, Massachusetts London, England,pp. 109-110.
http://www-stat.stanford.edu/~susan/surprise/Collector.html
http://www-stat.stanford.edu/~susan/surprise/Collector.htmlhttp://www-stat.stanford.edu/~susan/surprise/Collector.htmlhttp://www-stat.stanford.edu/~susan/surprise/Collector.htmlhttp://www-stat.stanford.edu/~susan/surprise/Collector.htmlhttp://www-stat.stanford.edu/~susan/surprise/Collector.htmlhttp://www-stat.stanford.edu/~susan/surprise/Collector.htmlhttp://www-stat.stanford.edu/~susan/surprise/Collector.html