The recursive function defined as so:
function factrec($x) {
if($x <= 1) {
return $x;
} else {
return $x * factrec($x - 1);
}
}
And iterative here:
function factiter($x) {
$y = $x;
while($y > 1) {
$x *= ($y - 1);
$y--;
}
return $x;
}
I had read that on the recursive function the body is O(1) and the recursive calls O(n-1) making it O(n), but for the iterative is it O(n) as well?