1 / 11

C oupon collector’s problem

C oupon collector’s problem. CS658 Po- Ching Liu. Question . A person trying to collect each of b different coupons must acquire approximately x randomly obtained coupons in order to succeed. find x . Balls and bins. 1 st question:

rianne
Download Presentation

C oupon collector’s problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • 1st question: If n identical balls are tossed randomly into b bins, thenhow many balls willfall 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(withoutsuccess)=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 1st 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 • intcardcnt = 0; • // total number of cards collected • intvalcnt = 0; • // number of distinct cards • // repeatedly choose a random card and check whether it's a new one • while (valcnt < N) { • intval = (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.html

More Related