Re: some interview questions
- From: Denis Feldmann <denis.feldmann.asupprimer@xxxxxxxxxxxxxxxx>
- Date: Tue, 12 Sep 2006 13:36:10 +0200
William Hughes a écrit :
David R Tribble wrote:
How come no one has attempted an answer to (2)?
Because it is rather harder :)
Recall the question is;
2. Suppose you have a function that returns random 64-bit integers
without checking if a particular integer has already been used. How
many integers would be returned before the probability that an
integer
has been repeated is above 0.5?
This is, of course, the birthday problem. But with the very large
2^64,
computation of the exact answer is not practical,
so an approximation
is
needed.
A very rough approximation can be made by saying that if I choose N
numbers
I get N(N-1)/2 pairs. Since each pair has a 1/2^64 chance of matching,
I need about 2^63 pairs to get a probability of 1/2 (I did say very
rough),
so I need N(N-1) = 2^64, so N is about 2^32.
More careful analysis shows that this is only off by about 20%.
However, even the rough solution indicates
the important fact that given X uniformly distributed outcomes,
one needs about sqrt(x) tries to get a repeat, and the interviewer.
would probably be satisifed.
In fact, you are looking for n such that P= prod (N-k)/N (k=0..n-1) =0.5, with N=2^64. P=N^-n N!/(N-n)!, and Stirling formula will give a very good approximation of that
.
-William Hughes
- Follow-Ups:
- Re: some interview questions
- From: William Hughes
- Re: some interview questions
- References:
- some interview questions
- From: Digital Puer
- Re: some interview questions
- From: Jim Gibson
- Re: some interview questions
- From: M.J.T. Guy
- Re: some interview questions
- From: David R Tribble
- Re: some interview questions
- From: William Hughes
- some interview questions
- Prev by Date: Re: How do we convert inequalities constraints using lagrange multipliers?
- Next by Date: Re: Complete metric quotient spaces
- Previous by thread: Re: some interview questions
- Next by thread: Re: some interview questions
- Index(es):
Relevant Pages
|