Calculating Pascal's Triangle N-th row - why does this work?

54 Views Asked by At

I encountered this solution to the problem in the title (calculate Pascal's Triangle $N$-th row). The main point is the calculation within the loop - I am trying to figure out the meaning of it:

For every $0\leqslant i\leqslant n$: $$\alpha_0 = 1,\quad \alpha_i = \dfrac{\alpha_{i-1}(a+i-1)}{i}.$$

Why is it correct? I assume its related to the binomial coefficients in a way. Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

I suspect your formula there is related to alisianoi's solution to this SO question on efficient binomial computation. Note in the code comments, you have the following:

Use an iterative approach with the multiplicative formula:

$$\frac{n!}{k!(n - k)!} = \frac{n(n - 1)\dots(n - k + 1)}{k(k-1)\dots(1)} = \prod_{i = 1}^{k}\frac{n + 1 - i}{i}$$

Also rely on the symmetry:

$C_n^k = C_n^{n - k},$

so the product can be calculated up to 

$\min(k, n - k).$