Coupon collector’s problem CS658 Po-Ching Liu. Question A person trying to collect each of b different coupons must acquire approximately x randomly obtained.

Slides:



Advertisements
Similar presentations
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Advertisements

Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture22.
Insertion Sort by: Jordan Mash CS32 Bryce Boe. How does it work? Essentially the same way you order anything in day to day life. –Cards –Straws –Arrays?
Probabilistic Analysis and Randomized Algorithm. Worst case analysis Probabilistic analysis  Need the knowledge of the distribution of the inputs Indicator.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Repetition structures Overview while statement for statement do while statement.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
Data Structure TA: Abbas Sarraf
Jan Art of Programming Yangjun Chen Dept. Business Computing University of Winnipeg.
1 Discrete Probability Hsin-Lung Wu Assistant Professor Advanced Algorithms 2008 Fall.
A tour around Java General introduction to aspects of the language (these will be covered in more detail later) After this tour you should have a general.
The break and continue statements. Introduction There are 2 special statements that can affect the execution of loop statements (such as a while-statement)
Shorthand operators.
Chapter 6: Iteration Part 2. Create triangle pattern [] [][] [][][] [][][][] Loop through rows for (int i = 1; i
Introduction to Object-Oriented Programming
Introduction to Testing 1. Testing  testing code is a vital part of the development process  the goal of testing is to find defects in your code  Program.
Chapter 6: Iteration Part 1. To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To understand.
The Rectangle Method. Introduction Definite integral (High School material): A definite integral a ∫ b f(x) dx is the integral of a function f(x) with.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
A Semantic Error in Google last weekend! Someone in Google typed an extra ‘/’ character into their URL List Link to CNN video report posted on Collab.
1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008.
1.4 Arrays "... By the way, we rank 10 th among the industrialized world in broadband technology and its availability. That’s not good enough for America.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
CS177 Week2: Recitation Primitive data types and Strings with code examples.
Mixing integer and floating point numbers in an arithmetic operation.
The Bisection Method. Introduction Bisection Method: Bisection Method = a numerical method in Mathematics to find a root of a given function.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
The while-statement. The loop statements in Java What is a loop-statement: A loop-statement is a statement that repeatedly executes statements contained.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
Java the UML Way version Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
ICS 353: Design and Analysis of Algorithms
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
A: A: double “4” A: “34” 4.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
The if-else statement. Introducing the if-else statement Programming problem: Re-write the a,b,c-formula program to solve for complex number solutions.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Probabilistic analysis
Introduction of Java Fikri Fadlillah, S.T.
Slides by Evan Gallagher
Slides by Evan Gallagher
An Introduction to Java – Part I
Computing Adjusted Quiz Total Score
An Introduction to Java – Part I, language basics
The Boolean (logical) data type boolean
AP Java Warm-up Boolean Array.
class PrintOnetoTen { public static void main(String args[]) {
Lecture Notes – Week 4 Chapter 5 (Loops).
Introduction to Object-Oriented Programming
1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2010 · 2/6/11 12:33.
Repetition Statements
The for-statement.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
LCC 6310 Computation as an Expressive Medium
Computer Science Club 1st November 2019.
Presentation transcript:

Coupon 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: If n identical balls are tossed randomly into b bins, then how many balls will fall in a given bin? Ans:

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

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]

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))

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.

proof E[# of tosses in the ith stage]= E[total # of tosses in the 1 st to the bth stage] =

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.

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); }

references Thomas H. Cormen,Charles E. Leiserson, Ronald L. Rivest, Clifford Stein(1990), Introduction to Algorithms, The MIT Press, Cambridge, Massachusetts London, England, pp stat.stanford.edu/~susan/surprise/Collector.ht ml stat.stanford.edu/~susan/surprise/Collector.ht ml