Think of your friends and who-knows-whom. Draw a dot for each person and a line between any two who are friends. That picture — dots and lines — is a graph, and it is one of the most useful objects in all of mathematics. The same picture models a road map (towns joined by roads), the internet (computers joined by cables), a molecule (atoms joined by bonds), and a family tree. Wherever "things" are "connected", a graph is hiding.
The remarkable thing is that a graph forgets everything except the connections. It does not care where you draw the dots, how long the lines are, or whether they curve — only who is joined to whom. That ruthless simplicity is exactly what makes graphs so powerful: one idea, one picture, a thousand different worlds.
A graph is built from two
A graph is a pair
For example,
Here is that exact graph. Step through: first the edges appear, then each vertex is labelled with its degree — the number of edges touching it — and finally we add those degrees up. Watch what number comes out.
The vertices themselves can sit anywhere — drag the whole picture in your mind, stretch the lines — and it is still the same graph, because the set of edges has not changed.
The degree of a vertex, written
Degree is a first, cheap measure of importance. In a social network, high-degree people are the connectors; in a road map, a high-degree town is a busy junction. And once you can count degrees, a beautiful, unbreakable law appears.
Add up the degrees of every vertex and you always get the same magic answer: twice the number of edges.
For any graph
Why is it true? Look at any single edge, say
Check it on our example: the degrees are
Picture a party where some people shake hands. Make a graph: a vertex per guest, an edge per
handshake. A guest's degree is how many hands they shook. Every handshake involves exactly
two hands, so when you total everyone's tally you have counted each handshake twice — the sum of
degrees is
The punchline: the number of people who shook an odd number of hands is always even. You can walk into any room in the world, and this is guaranteed true without counting a thing. That is the quiet power of a proof.
Our first example was a simple graph: at most one edge between any two vertices, and no edge from a vertex back to itself. Most of the time "graph" means "simple graph". But two other creatures are allowed if we relax the rules:
A graph that permits loops or parallel edges is a multigraph. The Handshake Lemma
still holds for multigraphs — every edge, loop and all, contributes exactly
In earlier maths you drew "graphs" like
A graph-theory graph has no axes, no coordinates, and no notion of distance. It is just dots and connections. When you place the dots on a page you may put them anywhere — the maths does not change. So when someone says "graph", check which world you are in: a plotted curve, or a network of vertices and edges. On this page — and in all of graph theory — it always means the latter.
Because a graph is two sets, a computer stores it directly. Here we list the edges, count how many touch each vertex to get the degrees, and confirm the Handshake Lemma — the sum of degrees comes out to twice the edge count. Press Run.