Matrices

Problem shape

Beginner
0,0
0,1
0,2
0,3
1,0
1,1
1,2
1,3
2,0
2,1
2,2
2,3
Core idea

Visit each cell using nested row and column loops.

Step 1 / 5
Problem shape
Current lesson

Matrix Traversal Lab

Matrices Beginner

Matrix Traversal

Welcome to the Matrix Traversal algorithm lab. Visit each cell using nested row and column loops. Use it when: Use for grids, tables, image-like data, and DP matrices. The time complexity is O(R*C), and the space complexity is O(1). The pseudocode is: for r from 0 to rows - 1 for c from 0 to cols - 1 visit grid[r][c] As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(R*C)

Space

O(1)

Pseudocode

for r from 0 to rows - 1
  for c from 0 to cols - 1
    visit grid[r][c]
Open deeper structure lesson
1.0x