A Graphs
08 — Data Structures
Vertices, edges & traversal

The Graph

Dots connected by lines — that's it. No root, no order, no hierarchy. Just relationships. The shape behind maps, social networks, and the web itself.

A graph is a set of vertices (the dots) joined by edges (the lines). Unlike a tree, there is no root and no parent-child rule — any vertex can connect to any other, and cycles are allowed. Edges can be directed (one-way) or undirected (two-way), and weighted with a cost. Two vertices joined by an edge are neighbors. To explore a graph you traverse it: breadth-first spreads outward in rings, while depth-first plunges down one path before backtracking. Both visit every vertex and edge once — O(V + E).

Try it in 3D

Each labelled orb is a vertex; each line is an edge. The vertices float in real 3D space — drag to orbit and see the network from every angle.

Drag to rotate — scroll to zoom
Press an operation above.ready
Current vertex Neighbors BFS visit DFS visit

Concepts & operations

How a graph is stored decides what is cheap — and traversal is the engine behind most graph algorithms.

Cost cheat sheet

Adjacency list vs matrix is the central trade-off: space against edge-lookup speed.