This trace uses the technique demonstrated in tracing recursive methods and some of the material from the more complex stack based trace with nested recursive calls. Familiarity with the material from those resources is assumed, including the notation.

The same trace is available with each step on its own page, starting with Step 1.

Step 1: initial call

Initial call stack

r(32)

Step 2: recur(32)

Resulting call stack

r(10)
r(32)    dig -> "2"    "2" + ____

Step 3: recur(10)

Resulting call stack

r(3)
r(10)    dig -> "1"    "1" + ____
r(32)    dig -> "2"    "2" + ____

Step 4: recur(3)

Resulting call stack

r(1)
r(3)     dig -> "0"    "0" + ____
r(10)    dig -> "1"    "1" + ____
r(32)    dig -> "2"    "2" + ____

Step 5: recur(1)

Resulting call stack

r(1)  returns "1"
r(3)     dig -> "0"    "0" + ____
r(10)    dig -> "1"    "1" + ____
r(32)    dig -> "2"    "2" + ____

Step 6: Back in recur(3)

Resulting call stack

r(1)  returns "1"
r(3)     dig -> "0"    "0" + "1"  returns "01"
r(10)    dig -> "1"    "1" + ____
r(32)    dig -> "2"    "2" + ____

Step 7: Back in recur(10)

Resulting call stack

r(1)  returns "1"
r(3)     dig -> "0"    "0" + "1"   returns "01"
r(10)    dig -> "1"    "1" + "01"  returns "101
r(32)    dig -> "2"    "2" + ____

Step 8: Back in recur(32)

Resulting call stack

r(1)  returns "1"
r(3)     dig -> "0"    "0" + "1"   returns "01"
r(10)    dig -> "1"    "1" + "01"  returns "101
r(32)    dig -> "2"    "2" + "101" returns "2101"