logo CodeStepByStep logo

recursion_mystery8

Language/Type: PHP recursion recursion mystery

For each call to the following recursive function, write the output that is produced as it would appear on the console. Hint: To a re-tracing out long chains of calls, it may help you to look at your own notes on call results that you have already previously computed, and re-use those results as applicable.

function recursion_mystery8($n) {
    if ($n <= 1) {
        print($n);
    } else {
        print("$n = (");
        recursion_mystery8(intval($n / 2) + $n % 2);
        print(", ");
        recursion_mystery8(intval($n / 2));
        print(")");
    }
}
recursion_mystery8(3);
recursion_mystery8(4);
recursion_mystery8(6);
recursion_mystery8(7);

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.