It is actually quite elegant.
The binomialCoeff function is a recursive function with two basic conditions. If k == 0 , you return only 1 . If n<=k , you return 0. Therefore, if the value does not match true, you call the same function, subtracting it from n and k . This is repeated as a result.
n * (binomialCoeff (n-1, k-1)) / k
So N is 10 and K is 7
You are getting
10*(binomialCoeff(9,6)/7)
Just to keep things simple, call the first time binomialCoeff is called res1. This simplifies:
10*(res1/6)
but res1 itself calls binomialCoeff
as a result
9*(binomialCoeff(8,5)/6)
which we can call res2
therefore, we get
10*(res2/6)
and so on, until you meet the basic conditions; whereby the series n is multiplied together.
source share