I am given the number of trees of size N with branching factor b and attempting to generate Catalans number without the use of a separate recursive function to generate the the number of nested for loops.
Ive tried this so far
int catalan(int size, int b)
{
int n = 0;
int c = b;
if (size < 2)
{
return 1;
}
if (b <= 0)
{
return n;
}
while(c--)
{
for (int s = 0; s < size; s++)
{
n += (catalan(s,b) * catalan(size-1-s-c, b) );
}
catalan(size--,c);
}
return n;
}
for a size of 4 and branching factor of 2 I expect this function to return 14 but instead I receive 21.
thanks in advance.