This trace uses the technique demonstrated in tracing recursive methods. Familiarity with that material is assumed.

Step 1: initial call

Initial call stack

f(6)

Step 2: f(6)

Resulting call stack

g(5)
f(6)

Step 3: g(5)

Resulting call stack

f(4)
g(5)
f(6)

Step 4: f(4)

Resulting call stack

g(3)
f(4)
g(5)
f(6)

Step 5: g(3)

Resulting call stack

f(2)
g(3)
f(4)
g(5)
f(6)

Step 6: f(2)

Resulting call stack

g(1)
f(2)
g(3)
f(4)
g(5)
f(6)

Step 7: g(1)

Resulting call stack

f(0)
g(1)
f(2)
g(3)
f(4)
g(5)
f(6)

Step 8: f(0)

Resulting call stack

f(0)  returns 0
g(1)
f(2)
g(3)
f(4)
g(5)
f(6)

Step 9: back in g(1)

Resulting call stack

f(0)  returns 0
g(1)  returns 1
f(2)
g(3)
f(4)
g(5)
f(6)

Step 10: back in f(2)

Resulting call stack

f(0)  returns 0
g(1)  returns 1
f(2)  returns 1
g(3)
f(4)
g(5)
f(6)

Step 11: back in g(3)

Resulting call stack

f(0)  returns 0
g(1)  returns 1
f(2)  returns 1
g(3)  returns 4
f(4)
g(5)
f(6)

Step 12: back in f(4)

Resulting call stack

f(0)  returns 0
g(1)  returns 1
f(2)  returns 1
g(3)  returns 4
f(4)  returns 4
g(5)
f(6)

Step 13: back in g(5)

Resulting call stack

f(0)  returns 0
g(1)  returns 1
f(2)  returns 1
g(3)  returns 4
f(4)  returns 4
g(5)  returns 9
f(6)

Step 14: back in f(6)

Resulting call stack

f(0)  returns 0
g(1)  returns 1
f(2)  returns 1
g(3)  returns 4
f(4)  returns 4
g(5)  returns 9
f(6)  returns 9