Which function grows faster, exponential or factorial?
154 n! eventually grows faster than an exponential with a constant base (2^n and e^n), but n^n grows faster than n! since the base grows as n increases.
154 n! eventually grows faster than an exponential with a constant base (2^n and e^n), but n^n grows faster than n! since the base grows as n increases.
You can search for (1…100)! on Wolfram|Alpha to pre-calculate the factorial sequence. The first 100 numbers are: If you still want to calculate the values yourself, you can use memoization: Edit: 21.08.2014 Solution 2 I thought it would be useful to add a working example of lazy iterative factorial function that uses big numbers to get exact result with memoization and cache as comparison I assume you would use some kind … Read more
return factValue * printFactorial(factValue – factCounter); I assume that you should be using the “next” values instead of these. Edit: Also note that the function takes two parameters and is void. Returning factValue times void doesn’t make sense.
There you go. This is probably the most trivial example of a function that runs in O(n!) time (where n is the argument to the function):