I mean to say, what's the most efficient code possible to write for calculating the sum of binomial coefficients n choose k, where n is fixed and you only want the sum to the first k terms, knowing that k < n.
For example, if n = 4 and k = 2 then you should receive 11 because it'll be 1 + 4 + 6. Most of the code I've been able to find is just written for computing a single binomial coefficient rather than a partial sum, or is giving some sort of approximation that works well for large numbers but not small ones.
This is a linear answer for the question:
First we prove that (nC(k+1))/(nCk) = (n-k)/(k+1)
Now we can find kCn using (k-1)Cn in a constant time:
As we know 1Cn is always equal to n. So we can find the sequence(and sum of the sequence) of 1Cn ... kCn in a linear time: