COURSE / REAL PRACTICE
Visual graph traversal in Python
Animate breadth-first and depth-first search on a grid, reconstruct parent paths and export a replayable trace.
Read the explanation and diagrams, then work through the practice. Your browser profile supplies your saved progress.
What you’ll work toward
Export tested BFS/DFS traversal events and replay them in a step/pause/reset grid visualizer. Explain shortest paths in unweighted graphs, DFS limits, unreachable goals and deterministic neighbor order.
Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.
Before you start
This course builds on these skills:
Individual lessons can add prerequisites. Your lesson progress shows your actual readiness.
A look inside the first lesson
A grid is a graph of legal moves
rows = ["...", ".#.", "..."]
row, col = 0, 0
for dr, dc in [(-1,0),(0,1),(1,0),(0,-1)]:
nr, nc = row + dr, col + dc
if 0 <= nr < len(rows) and 0 <= nc < len(rows[0]) and rows[nr][nc] == ".":
print((nr,nc))Your lesson sequence
Follow the same units and lessons in either view. Prerequisite links and your practice progress stay with each lesson.
A grid is a graph
- LESSON 01.01
A grid is a graph of legal moves
Represent walkable cells and return only in-bounds orthogonal neighbors in a fixed order.
Open lesson - LESSON 01.02
Separate frontier, discovered cells and parents
Initialize search state without confusing queued work, completed expansion and the first-discovery tree.
Open lesson
Queues, stacks and parents
- LESSON 02.01
Use a queue for breadth-first search
Expand FIFO layers and keep the first parent to obtain minimum-edge paths in this unweighted grid.
Open lesson - LESSON 02.02
Use a stack for depth-first search
Explore a deterministic LIFO branch, prevent duplicate discovery and recognize that DFS paths need not be shortest.
Open lesson - LESSON 02.03
Reconstruct a route from first parents
Follow the discovery tree backward, reverse the chain and reject cycles instead of confusing expansion order with a path.
Open lesson
Robust searches and visual traces
- LESSON 03.01
Handle cycles, unreachable goals and deterministic ties
Choose BFS or DFS explicitly, reconstruct only found routes and return a clear unreachable result.
Open lesson - LESSON 03.02
Export a traversal and replay it visually
Serialize real search snapshots into bounded JSON and drive a step/pause/reset visualizer without executing code in the browser.
Open lesson