I discovered this issue by implemented the algorithm from this post: Example of O(n!)?
I tried counting the operations though, and the algorithm loops 64 times when calculating 4! (which is 24).
Is there something I'm missing? Or does this algorithm really just have a run-time complexity that is not O(n!)
var operations = 0;
function factorial(n) {
for (let i = 0; i < n; i++) {
operations++;
factorial(n - 1);
}
}
console.log(factorial(4))
console.log('operations: ', operations) // prints 64 operations