Algorithms and Data Structures · Junior · Question 69 of 75
What is a matrix (2D grid) usually represented as in JavaScript?
- ✓Correct answer: An array of arrays, accessed as
grid[row][col] - 2A
Setof numbers, one per cell - 3One long string with rows separated by commas
Explanation
Grids show up in many problems: maps, game boards, images. Each cell often has up to four neighbors (r±1, c) and (r, c±1), so a grid is also a graph that can be traversed with BFS or DFS.