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.
Skills Tested
What this FRQ is really practicing
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
- 1Part A: if only the right neighbor exists, return its Location.
- 2If only the below neighbor exists, return its Location.
- 3If both neighbors exist, compare their grid values and return the Location of the smaller value.
- 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
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
