logo CodeStepByStep logo

recursion_mystery11

Language/Type: PHP recursion recursion mystery

For each of the calls to the following recursive function below, indicate what output is produced:

function recursion_mystery11($n) {
    print("( ");
    helper($n);
    print(") ( ");
    helper($n);
    print(")");
}

function helper($n) {
    if ($n <= 1) {
        print("$n  = ");
    } else {
        print(($n % 2) . " ");
        helper(intval($n / 2));
        print("$n ");
        $n = $n - 1;
    }
}
recursion_mystery11(8);
recursion_mystery11(25);
recursion_mystery11(46);

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.