BEGINNER · 10 MIN · FREE LESSON
Graph representations
Explore graph representations through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore graph representations through a visual, step-by-step model.
Loading interactive lesson…
Enter {"n":5,"edges":[[0,1,2],[1,2,3],[0,3,1],[3,4,2]],"directed":false,"start":0,"target":4}. Vertices are 0 through n−1.
The same graph can be represented by edges, neighbor lists or a matrix.
Lists store only actual outgoing neighbors; matrices allocate every pair, including absent edges. Zero-weight edges require a separate absence marker.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
A road atlas can list roads, list neighbors or mark every pair on a grid.
The same links, three representations. Edit the graph JSON to add a cycle, isolate a vertex or change an edge weight. Nodes are numbered from zero.
Predict the next frontier decision or edge operation before revealing it. Compare a connected graph with the same graph after removing an important edge.
Lists take O(V+E) space; a matrix takes O(V²). An adjacency list spends storage on vertices and existing edges. A matrix indexes pairs directly but allocates every possible pair. The counters count teaching operations; animation duration is not a CPU benchmark.
The four references show the core operation. Adjacency-list inputs use zero-based vertex indices. Weighted references use (neighbor,weight) pairs or explicit edge triples. Validate the graph assumptions before calling standalone code.
Use a matrix for dense pair lookups and a list for sparse neighbor traversal.
A zero-cost edge exists; null means absent.
Check the graph assumptions, invariant and boundary conditions below.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.