Alex C.

asked • 05/26/20

Recursive Function Tracing

Consider the following recursive functions.

public static int square(int n) {
if (n == 0) return 0;
return square(n-1) + 2*n - 1;
}

public static int cube(int n) {
if (n == 0) return 0;
return cube(n-1) + 3*(square(n)) - 3*n + 1;
}


Write out the steps of the program (TRACE not run program) in order to find the value of:

  1. square(5)?
  2. cube(5)?
  3. cube(123)?


1 Expert Answer

By:

Patrick B. answered • 05/26/20

Tutor
4.7 (31)

Math and computer tutor/teacher

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.