AP CSA 2016 FRQ 3 Crossword
AP CSA 2016 FRQ 3: Crossword
Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF
| Question Type | 2D Array Operations |
| Key Skills | Write the Crossword class: canPlaceWordAt() checks whether a word fits in a given direction without conflicting with exi |
| Difficulty | Hard |
| AP CSA Units | Unit 4: Data Collections (2D array mutation, char comparison, boundary conditions). |
What This Problem Asks
Write the Crossword class: canPlaceWordAt() checks whether a word fits in a given direction without conflicting with existing filled cells; placeWord() fills the cells; and the constructor uses both to build the board.
Official Question & PDF
PDF cannot display here. Open PDF directly →
Provided Code
public class Crossword
{
private char[][] grid;
public Crossword(int rows, int cols) {
grid = new char[rows][cols];
}
public boolean canPlaceWordAt(String word, int row, int col, boolean across)
{ /* to be implemented */ }
public void placeWord(String word, int row, int col, boolean across)
{ /* to be implemented */ }
}
canPlaceWordAt & placeWord (9 Points)
Write canPlaceWordAt() (return true if the word fits without char conflict: each cell is either empty or already has the correct letter) and placeWord() (fill the cells with the word's characters).
Scoring Rubric
| +1 | Checks bounds: word fits within grid dimensions |
| +1 | Handles across=true: checks/fills row cells |
| +1 | Handles across=false: checks/fills column cells |
| +1 | Returns false if a cell has a different non-empty char |
| +1 | Returns true if all cells are empty or matching |
| +1 | placeWord fills each cell with the correct char |
| +1 | placeWord handles across vs. down correctly |
| +1 | placeWord does not write outside array bounds |
| +1 | Algorithm: canPlaceWordAt and placeWord both correct |
Solution
public boolean canPlaceWordAt(String word, int row, int col, boolean across)
{
for (int i = 0; i < word.length(); i++)
{
int r = across ? row : row + i;
int c = across ? col + i : col;
if (r >= grid.length || c >= grid[0].length)
return false;
char cell = grid[r][c];
if (cell != '\0' && cell != word.charAt(i))
return false;
}
return true;
}
public void placeWord(String word, int row, int col, boolean across)
{
for (int i = 0; i < word.length(); i++)
{
int r = across ? row : row + i;
int c = across ? col + i : col;
grid[r][c] = word.charAt(i);
}
}
Common Mistakes to Avoid
Wrong
if (cell != ' ' && cell != word.charAt(i)) // wrong — empty cells are '\0'
Correct
if (cell != '\0' && cell != word.charAt(i)) // correct
char arrays are initialized to '\0' (null character, value 0), not ' ' (space, value 32). Checking for space misses empty cells entirely.
Wrong
char cell = grid[r][c]; // may throw ArrayIndexOutOfBoundsException
Correct
if (r >= grid.length || c >= grid[0].length) {
return false; // check first
}
Always verify the computed row and column are within grid bounds before accessing the cell.
Exam Tips
Frequently Asked Questions
What does 2016 AP CSA FRQ 3 Crossword ask?
It asks students to write canPlaceWordAt() (check that a word fits at a position in a given direction without conflicting with existing chars) and placeWord() (fill those cells with the word's characters), handling both horizontal and vertical placement.
What is the default value of a char in a Java char array?
The default value is '\0' (the null character, Unicode value 0). It is not a space ' '. Checking for space instead of '\0' is the most common error on this FRQ.
See All 2016 AP CSA FRQs
View the complete 2016 exam hub with solutions, difficulty analysis, and scoring for all four questions.
View 2016 FRQ Hub →Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]