Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest
 Share

Question

You need to select one among p persons in a fair manner - i.e, probability of choosing any one should be 1/p. You have a fair coin at your disposal.

Assume p is not of the form 2N for some positive N.

a. What will be your strategy for least number of coin tosses? What is this least number?

b. What will be the average number of coin tosses?

b. Can you solve for the generic case, where you have to choose one among p persons, assuming you have a rand() function that returns a random number between 1 to q with uniform probability?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Write the number p in binary.

It will have n digits, where n = log2(p).

Flip the coin n times, calling heads=1 and tails=0, to spell out a number.

Discard the result if the number is greater than p.

That gives a fair selection of numbers 1-p.

But it's probably not done with the fewest possible coin tosses.

This method avoids possibly throwing out a result.

Divide the interval [0,1] into p equal parts. The intervals are [0, 1/p), [1/p, 2/p), ... [(p-1)/p, p].

Find the number of digits in the binary representation of 1/p and toss the coin that many times.

The string of digits will define a number in [0, 1] with equal probability of falling in any of the p segments.

This produces a fair selection among p choices.

Link to comment
Share on other sites

  • 0

Write the number p in binary.

It will have n digits, where n = log2(p).

Flip the coin n times, calling heads=1 and tails=0, to spell out a number.

Discard the result if the number is greater than p.

That gives a fair selection of numbers 1-p.

But it's probably not done with the fewest possible coin tosses.

This method avoids possibly throwing out a result.

Divide the interval [0,1] into p equal parts. The intervals are [0, 1/p), [1/p, 2/p), ... [(p-1)/p, p].

Find the number of digits in the binary representation of 1/p and toss the coin that many times.

The string of digits will define a number in [0, 1] with equal probability of falling in any of the p segments.

This produces a fair selection among p choices.

:) First one is correct (and that is the only method I know). I think the second one may not be a solution..

1/p in binary may not terminate.

Link to comment
Share on other sites

  • 0

:) First one is correct (and that is the only method I know). I think the second one may not be a solution..

1/p in binary may not terminate.

Let me refine bonanova's approach a bit

Let head=1, tail = 0. Suppose that you flipped a coin three times, and the number x turn out as .101. If you continue flipping until infinity, the number x must belong in the interval [ .10100000000..., .1011111111111...], which has a width of 1/2n, n being the number of flips. So we revise bonanova's strategy as follow

1) Divide the interval into p parts [0, 1/p), [1/p, 2/p), ... [(p-1)/p ].

2) Flip the coin as many times as it takes. Update the value of x at every turn.

3) Stop flipping once the interval [x, x + 1/2n ] belongs entirely within one of the p intervals from part 1).

I'll work on the optimal part later. Need to do other work that actually paids for now.

Edited by bushindo
Link to comment
Share on other sites

  • 0

Write the number p in binary.

It will have n digits, where n = log2(p).

Flip the coin n times, calling heads=1 and tails=0, to spell out a number.

Discard the result if the number is greater than p.

That gives a fair selection of numbers 1-p.

But it's probably not done with the fewest possible coin tosses.

This method avoids possibly throwing out a result.

Divide the interval [0,1] into p equal parts. The intervals are [0, 1/p), [1/p, 2/p), ... [(p-1)/p, p].

Find the number of digits in the binary representation of 1/p and toss the coin that many times.

The string of digits will define a number in [0, 1] with equal probability of falling in any of the p segments.

This produces a fair selection among p choices.

I prefer the second method too.

In the first method, the probability of choosing one person out of p is not 1/p but 1/2n where n is the smallest number such that 2n is greater than p (mentioned by bonanova as discarding outputs greater than p).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...