# 2004 AP CS AB MC #33 solution

As noted in the 2004 AB MC explanations, this problem is more appropriately solved using the technique presented in analyzing recursive methods. The trace below is presented as a demonstration of tracing. It is not a suggestion that this problem should be traced.

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.

## Step 1: Initial call

### Initial call stack

``````m(2, 3)
``````

## Step 2: `mystery(2, 3)`

• Checks if `2 != 0`, which is `true`, so the entire condition is `true`
• Computes `mat[2][3]`, which is `11`, `+ ____` (something unknown)
• Calls `mystery(2 - 1, 3 - 1)`, which is `mystery(1, 2)`

### Resulting call stack

``````m(1, 2)
m(2, 3)    11 + ____
``````

## Step 3: `mystery(1, 2)`

• Checks if `1 != 0`, which is `true`, so the entire condition is `true`
• Computes `mat[1][2]`, which is `6`, `+ ____`
• Calls `mystery(1 - 1, 2 - 1)`, which is `mystery(0, 1)`

### Resulting call stack

``````m(0, 1)
m(1, 2)    6 + ____
m(2, 3)    11 + ____
``````

## Step 4: `mystery(0, 1)`

• Checks if `0 != 0`, which is `false`, or `1 != 0`, which is `true`, so the entire condition is `true`
• Computes `mat[0][1]`, which is `1`, `+ ____`
• Calls `mystery(0 - 1, 1 - 1)`, which is `mystery(-1, 0)`

### Resulting call stack

``````m(-1, 0)
m(0, 1)    1 + ____
m(1, 2)    6 + ____
m(2, 3)    11 + ____
``````

## Step 5: `mystery(-1, 0)`

• Checks if `-1 != 0`, which is `true`, so the entire condition is `true`
• Accesses `mat[-1][0]`, which throws an `ArrayIndexOutOfBoundsException`