Download presentation

Presentation is loading. Please wait.

Published byMyles Harris Modified over 3 years 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

OK

Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.

Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Download ppt on space exploration Ppt on mobile and wireless networks Ppt on data abstraction in java Download ppt on life process for class 10 cbse all 10 Ppt on mahatma gandhi in hindi Ppt on blood and its components Ppt on event driven programming wiki Ppt on role of mass media in education Ppt on how to improve communication skills in english Ppt on 3 idiots learning