Log inStart free
LESSON 3.06 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Graphs and traversal

Watch BFS spread through a grid in rings while DFS follows one route deep.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 3.06 · GRAPH BAY12 NODES · 16 EDGES · SHORT WALL
01
Stage 1 of 6 · Nodes and edges
A graph is nodes joined by edges. Each grid cell is a node; each open move is an edge.
Explain it simply

Think of a small map, like the gridworlds that RL agents move around in. Each cell, A to L, is a node, and a line between two cells is an edge. The grey bar is a wall, so no edge joins B and C. Here, every edge counts as one step.

A 4 by 3 grid of 12 nodes, A to L. 16 edges join cells that are side by side. The short wall blocks B to C. The search starts at F; the goal is D.

node, edgefrontier (ring), finished node, search treepathcheck of a seen nodemove a wall blocks
graphABCDgoalEFstartGHIJKL|E| = 17 moves − 1 blocked = 16graphABCDgoalEFstartGHIJKL|E| = 17 moves − 1 blocked = 16
Toy: the 3.C1 grid · 12 nodes · start F, goal D · no edge costs
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
G=(V, E)G = (\sy{V}{ink}{V},\ \sy{E}{ink}{E})
∣V∣=12,∣E∣=17−1=16|V| = 12,\quad |E| = 17 - 1 = 16

A graph is a set of nodes and a set of edges.

Common mix-ups

MYTHDFS also finds the shortest path.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With the short wall, is the DFS path to D a shortest path?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.