TheAlgorithms / C-Sharp

All algorithms implemented in C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BinomialCoefficient.cs

deljohnson1 opened this issue · comments

Algorithms.Numeric.BinomialCoefficient.Calculate is significantly limited by the inputs being int and the return value being long.; all should be BigInteger.

It can easily be optimized by not doing the extra calculations of factorial divided by factorial.

Error handling should be outside of this function for performance reasons, particularly sequences. Error exception references n when the inputs are num and k.

My test environment doesn't show this change breaking anything.

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

I've opened a pull request which fixes all of the issues mentioned above except for the sanity check for the input variables. In my opinion these checks should be present in a reference implementation. And to be honest I don't think these checks should be too hard on the performance; removing all the unnecessary multiplications and divisions should already fix the performance issues even in sequences.

@deljohnson1 Feel free to double check the performance during the computation of sequences and report back whether there are any serious performance implications based on the sanity check for num and k.