AP CSA FRQ Guide

2024 FRQ 4: GridPath

Write two methods for a path through a 2D array. One chooses the next Location by comparing the right and below neighbors. The other repeatedly follows those choices and returns the sum of values on the path.

2D Arrays and Path Traversal22 minute target2D arraysobjectspath traversalhelper methodsloops

Skills Tested

What this FRQ is really practicing

2D arraysobjectspath traversalhelper methodsloops

Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.

Starter Approach

How to begin without copying a solution

  1. 1Part A: if only the right neighbor exists, return its Location.
  2. 2If only the below neighbor exists, return its Location.
  3. 3If both neighbors exist, compare their grid values and return the Location of the smaller value.
  4. 4Part B: add the starting cell, repeatedly call getNextLoc, move to that Location, and stop at the bottom-right cell.

Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.

Common Mistakes

Mistakes to watch for while writing

Returning the smaller value instead of returning a Location object.
Forgetting edge cases when the current cell is in the last row or last column.
Comparing the current cell with a neighbor instead of comparing the two possible neighbors.
Not including the starting cell in sumPath.
Calling getNextLoc but failing to update row and col before continuing.

Self Check

Review questions before you submit

Defines getNextLoc with Location return type and row/col parameters.

Part A returns a Location object.

Handles the last-row case by returning the right neighbor.

If there is no row below, move right.

Handles the last-column case by returning the below neighbor.

If there is no column to the right, move down.

Compares the right and below neighbor values.

When both neighbors exist, compare grid[row][col + 1] with grid[row + 1][col].

Returns new Location objects with the chosen row and column.

Create a Location for the selected neighbor.

Defines sumPath with int return type and row/col parameters.

Part B returns a numeric sum.

Initializes the sum with the starting grid value.

The path includes the starting cell.

Loops until reaching the last row and last column.

Stop only after the path reaches the bottom-right cell.

Practice Links

Where to go next