Matrix Traversal Visualizer

Step through spiral matrix traversal or BFS on a grid, then inspect visited cells, frontier cells, coordinates, and the traversal order.

Rows
4
Cols
4
Visited
0
Frontier
0

Matrix input

Step controls

Step 1 of 18: Start spiral traversal with top=0, bottom=3, left=0, right=3.

Matrix diagram

Start spiral traversal with top=0, bottom=3, left=0, right=3.

Current Frontier Visited
1 0,0
2 0,1
3 0,2
4 0,3
5 1,0
6 1,1
7 1,2
8 1,3
9 2,0
10 2,1
11 2,2
12 2,3
13 3,0
14 3,1
15 3,2
16 3,3

Traversal order

No cells visited yet.

Traversal rule

Spiral order visits the top row, right column, bottom row, and left column, then repeats inward until every cell is visited.

What is a Matrix Traversal Visualizer?

A matrix traversal visualizer shows how an algorithm visits cells in a 2D grid. It helps connect row and column indexes with the visible order of traversal.

This tool includes spiral order traversal and grid BFS from a selected starting cell. It is useful for learning matrix problems, grid search, queues, and coordinate-based algorithms.

For the full cluster of related tools, browse the Data Structure Visualizers hub.

How to use this matrix traversal visualizer

  • Paste a grid with one row per line.
  • Choose spiral order or BFS mode.
  • Set a starting row and column for BFS mode.
  • Step through visited cells, frontier cells, and traversal order.
  • Compare the highlighted grid with the coordinate log.

Matrix traversal and graph traversal

A grid can be treated as a graph where each cell is a node and adjacent cells are edges. BFS on a matrix uses the same queue pattern as BFS on an explicit graph, but the neighbors come from row and column offsets.

Compare this with the Graph BFS DFS Visualizer, Stack and Queue Visualizer, and Sliding Window Visualizer.

Frequently Asked Questions

What input format does this matrix visualizer use?
Paste one matrix row per line. Values can be separated by spaces or commas.
What does spiral traversal mean?
Spiral traversal visits the outer top row, right column, bottom row, and left column, then repeats inward.
What does grid BFS show?
Grid BFS shows the queue frontier expanding from the chosen starting cell to neighboring cells.
Can matrix values be letters?
Yes. Values can be numbers, letters, or short labels.

Related tools