Alex C.

asked • 05/26/20

Recursive Method Tracing

Consider the following recursive function.

public static void mystery(int n)
{
if (n == 0 || n == 1) return;
mystery(n-2);
System.out.println(n);
mystery(n-1);
}

Write out the steps of the program in order to find the value of mystery(6).

(Hint: First figure out what mystery(2)mystery(3), and so forth print out.)


2 Answers By Expert Tutors

By:

Kevin L. answered • 05/26/20

Tutor
4.9 (18)

BS Comp Sci with focus in Theory, Algorithms, and Machine Learning

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.