I'm calculating Bell's numbers using Bell's triangle (as calculating Stirling numbers of the 2nd kind is too slow) and my custom BigInteger class to solve this problem and I get the correct answer, however I'm getting TLE. I keep only prev and current lines of the triangle to lower memory usage. I also only calculate until the line I need to get the requested Bell number. The algorithm is:
Code: Select all
generateFirstLine();
while (!reachedTargetLine())
{
generateCurrLine();
prevLine = currLine;
}
number = currLine[0];
Are there optimizations to make in the algorithm or only in the add/copy methods of my BigInteger class?
Thanks