All lessons

Graphs

9 min · Dart examples

Represent nodes and edges with an adjacency list, then traverse to explore connections.

Dart · Graphs0/5 cleared

Enemy 1 of 5

This builds a small graph where each node lists its neighbors, then visits every node reachable from node 0 and counts them. Press Run to see the count, which should be 4.

Why this works

A graph is a set of nodes (vertices) and edges between them. An adjacency list maps each node to its neighbors, perfect for sparse graphs and interview problems.

Once you have adjacency, BFS and DFS from a start node count reachable nodes, detect cycles, or find paths.

You
Memory-Leak Rat
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.