Discrete Mathematics and Combinatorics

Graph Theory Introduced Through Networks You Already Know

Learn vertices, edges, paths and degrees using friendships, roads and web links, with one small network worked in full.

Key takeaways

  • A graph records objects as vertices and relationships as edges, and ignores shapes, distances and positions unless you add them.
  • Directed edges model one-way relationships, and weighted edges carry numbers such as time or cost.
  • The degree of a vertex counts its edges, and adding all degrees counts every edge twice.
  • Paths, cycles and connectedness describe how you can travel through a network.
  • The same abstract graph can be drawn in very different ways, so trust the list of edges over the picture.

Graph theory is the mathematics of things and the connections between them. A graph is a collection of points, called vertices, together with a collection of links, called edges, each of which joins two vertices. The word has nothing to do with the plots of functions you drew at school.

You already use graphs. A circle of friends, a subway map, a list of direct flights and the links between web pages are all graphs once you ignore everything except what is connected to what. That deliberate forgetting is what makes one theory serve so many subjects.

A small network to work with

Say five people, A through E, share a group project. A knows B and C. B also knows C. C knows D, and D knows E. As a graph, this has five vertices and five edges:

vertices:  A, B, C, D, E
edges:     AB, AC, BC, CD, DE

That list is the entire graph. You could draw C in the middle or off to one side, with straight lines or curved ones, and nothing mathematical would change. Subway maps work this way: they distort distances freely while keeping the order of stations and the transfer points correct.

The degree of a vertex is the number of edges meeting it. Here A, B and D have degree 2, C has degree 3 and E has degree 1. The degrees add to 10, exactly twice the number of edges. That is no accident, as the handshaking lemma explains.

Choosing the right kind of graph

Real relationships differ, so graphs come in several varieties.

Kind What changes Familiar example
Simple graph At most one edge per pair, no loops Mutual friendships
Multigraph Repeated edges allowed Two bridges joining the same banks
Directed graph Each edge has a direction One-way streets, web links
Weighted graph Each edge carries a number Road lengths or fares

A loop is an edge from a vertex to itself. In a directed graph you count two degrees at each vertex: the in-degree (arrows arriving) and the out-degree (arrows leaving). A page that many others link to has a high in-degree.

Before solving a problem, decide what the vertices are, what an edge means, whether direction matters and whether numbers are needed. Many difficulties disappear once this model is chosen well.

One idea, many everyday networks
Graph Vertices joined by edges Exams Courses joined if they share a student Power grid Stations joined by lines Friendships People joined if they know each other Roads Junctions joined by streets Web Pages joined by one-way links Graph Vertices joined by edges Friendships People joined if they know each other Roads Junctions joined by streets Web Pages joined by one-way links Power grid Stations joined by lines Exams Courses joined if they share a student

Walking through a network

A path is a route that follows edges from vertex to vertex without repeating a vertex. Its length is the number of edges used. In the project group, A, C, D, E is a path of length 3. A cycle is a route that returns to its start without otherwise repeating a vertex. A, B, C, A is a cycle of length 3, also called a triangle.

The distance between two vertices is the length of a shortest path between them. From A, the distances are 1 to B, 1 to C, 2 to D and 3 to E. The largest distance between any two vertices is the diameter, which here is 3.

A graph is connected if some path joins every pair of vertices. If not, it breaks into separate connected pieces called components. Remove edge CD from the example and it splits into two components, {A, B, C} and {D, E}. An edge whose removal disconnects something is a bridge. CD and DE are bridges. AB is not, because you can still travel from A to B through C.

In a road or computer network, bridges mark single points of failure. Engineers add redundant links to eliminate them.

Storing a graph

There are two standard ways to write a graph down for calculation. An adjacency list records the neighbors of each vertex:

A: B, C
B: A, C
C: A, B, D
D: C, E
E: D

An adjacency matrix is a square table with a 1 where two vertices are joined and a 0 where they are not:

A B C D E
A 0 1 1 0 0
B 1 0 1 0 0
C 1 1 0 1 0
D 0 0 1 0 1
E 0 0 0 1 0

The list saves space when each vertex has few neighbors, as in most large networks. The matrix answers "are these two joined?" immediately, and its powers count routes, a fact explored in adjacency matrices and counting walks.

Families worth recognizing

A few graphs appear so often that they have names.

  • The complete graph Kₙ joins every pair of n vertices. It has n(n − 1)/2 edges, so a round-robin league of 10 teams needs 45 matches.
  • The cycle graph Cₙ joins n vertices in a ring, with n ≥ 3.
  • A tree is a connected graph with no cycles, like a family of file folders. See trees and their key properties.
  • A bipartite graph splits its vertices into two groups with edges only between groups, such as applicants and jobs.

Two graphs are isomorphic if you can relabel the vertices of one to get exactly the edges of the other. Matching degrees is necessary but not sufficient. A ring of six vertices and a pair of separate triangles both have every degree equal to 2, yet one is connected and the other is not.

Questions graph theory answers

The subject traditionally dates to 1736, when Euler showed that no walk could cross each of the seven bridges of Königsberg exactly once. His reasoning appears in the Königsberg argument and grew into the study of Euler paths and circuits.

Other questions follow naturally from everyday needs:

  1. What is the quickest route? Dijkstra's algorithm answers this for nonnegative weights.
  2. What is the cheapest way to connect every site? This is the minimum spanning tree problem.
  3. How can exams be timetabled without clashes? That is graph coloring.
  4. How much traffic can a network carry from one place to another? Network flow theory addresses it.

Some of these have fast methods. Others, which sound just as innocent, have no known efficient solution in general.

A surprise about six people

Here is a taste of the reasoning. In any group of six people, there are either three who all know each other or three who are mutual strangers, assuming acquaintance goes both ways.

Pick one person, P. Among the other five, P either knows at least three or does not know at least three, by the pigeonhole principle. Suppose P knows Q, R and S. If any two of those three know each other, they form a trio with P. If no two do, then Q, R and S are mutual strangers. The case where P does not know three people works the same way with the roles swapped.

With five people the claim can fail: seat them in a ring where each knows only the two neighbors. This small result opens the door to Ramsey theory.

Turning a story into a graph

The skill that matters most is modeling: translating a situation into vertices and edges. Consider an old puzzle. A farmer must ferry a wolf, a goat and a cabbage across a river in a boat that holds the farmer and at most one of them. The wolf cannot be left alone with the goat, nor the goat with the cabbage.

Let each vertex be a safe situation, described by who is on the starting bank. Join two vertices if a single crossing turns one into the other. The puzzle "how do I get everyone across?" becomes "is there a path from the vertex with everyone on the starting bank to the vertex with nobody there?"

There are only 10 safe situations, so you can draw the whole graph on a napkin. A shortest path uses 7 crossings, and the key move is taking the goat back partway through. Searching the graph finds this without any flash of insight.

The same approach handles water jug puzzles, sliding tile games and the planning of tasks that must happen in a certain order. The vertices are states, the edges are legal moves and a solution is a path.

Why large networks behave differently

With millions of vertices, nobody inspects a drawing. People ask statistical questions instead: how degrees are distributed, how tightly neighbors cluster and how long typical distances are. Many social and technological networks have surprisingly short typical distances, often called the small-world property. A few long-range links are enough to shrink a large network dramatically.

Uneven degrees also produce effects that feel wrong. On average, your friends have at least as many friends as you do in a precise sense, because popular people appear on many lists. This is the friendship paradox.

Common beginner mistakes

  • Treating the drawing as the graph. Crossing lines in a picture do not create a new vertex.
  • Assuming edge length on paper means distance. Only stated weights carry numbers.
  • Forgetting direction. "A follows B" does not imply "B follows A".
  • Confusing a path with a walk. A walk may revisit vertices and edges, while a path may not.
  • Using different definitions without saying so. Books vary on whether "graph" permits loops and repeated edges, so check the convention first.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 45 articles in Discrete Mathematics and Combinatorics →

Latest news on this topic