I was given an algorithm and I was asked to estimate how often it would be called if I was trying to calculate ${100 \choose 50}0,25^{50}0.75^{50}$, the Binomial distribution of $50$ elements chosen within $100$ elements with $0.25$ their probability to appear.
This is the method:
binomial1(int N, int k, double p) {
if (N == 0 && k == 0) return 1.0;
if (N < 0 || k < 0) return 0.0;
return (1.0 - p) * binomial1(N-1, k, p)
+ p * binomial1(N-1, k-1, p);
}
The question is, how many calls to binomial1
would be required to evaluate binomial1(100, 50, 0.25)
?
I tried first the fool strategy to implements a system.out.println
within the code with an indice increasing each time the algorithm was called. But I realised that it was something fool when I noticed I reached:
passed 2485266 times
Thus I was wondering that as far that the algorithm is called twice every time it is called, I was wondering if it was simply called $2^{100}$ times? Yet, p*binomial1(N-1, k-1, p)
seemed to be called only $50$ times with a parameter $k=50$...
I'm only asking for a hint.
N
? – Raphael Dec 16 '15 at 14:43