Download presentation

Presentation is loading. Please wait.

Published byMyles Harris Modified about 1 year ago

1
Coupon collector’s problem CS658 Po-Ching Liu

2
Question A person trying to collect each of b different coupons must acquire approximately x randomly obtained coupons in order to succeed. find x

3
Balls and bins 1 st question: If n identical balls are tossed randomly into b bins, then how many balls will fall in a given bin? Ans:

4
Second Second question: Find the expected number of balls we need to toss (one ball for each toss) until a given bin contains a ball. The number of bins = b Ans: E = b

5
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]

6
Third the third question: Find the expected number of balls we need to toss (one ball for each toss) until every bin contains at least one ball? The number of bins = b Ans: E = b(lnb+O(1))

7
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
proof E[# of tosses in the ith stage]= E[total # of tosses in the 1 st to the bth stage] =

9
proof 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 coupons must acquire approximately x randomly obtained coupons in order to succeed.

10
Code by java compile: javac CouponCollector.java Run: 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); }

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.ht ml http://www- stat.stanford.edu/~susan/surprise/Collector.ht ml

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google