Introduction to Graph Theory
What You’ll Learn
Section titled “What You’ll Learn”In this lesson you’ll learn what a graph is in the discrete math sense, the vocabulary of vertices and edges, how degree works, the handshake theorem, and the common special graphs you’ll see over and over.
The Concept
Section titled “The Concept”A graph consists of a set of vertices (also called nodes) and a set of edges , where each edge connects a pair of vertices.
This has nothing to do with graphing functions. Here a graph is a picture of relationships: dots and the connections between them.
That’s a 4-vertex graph with 4 edges. Where you draw the dots on the page is irrelevant. Only the connections matter, which means the same graph can be drawn in wildly different-looking ways.
Here is a slightly bigger one with its degrees marked:
Core vocabulary
Section titled “Core vocabulary”- Adjacent - two vertices joined by an edge are adjacent, or neighbors.
- Incident - an edge is incident to the two vertices it connects.
- Degree - is the number of edges incident to . In the graph above, (edges to and ) and .
- Isolated vertex - degree 0. It exists but connects to nothing.
- Loop - an edge from a vertex to itself. It adds 2 to that vertex’s degree.
- Multiple edges - two or more edges joining the same pair. A graph with loops or multiple edges is a multigraph.
- Simple graph - no loops, no multiple edges. Unless stated otherwise, assume simple.
Directed versus undirected
Section titled “Directed versus undirected”In an undirected graph, edges have no direction. Friendship is symmetric: if is connected to , then is connected to .
In a directed graph (digraph), each edge is an arrow with a start and an end. Following someone on social media, one-way streets, and web links are all directed.
Directed vertices have two degrees:
- In-degree: arrows pointing in.
- Out-degree: arrows pointing out.
Weighted graphs
Section titled “Weighted graphs”A weighted graph attaches a number to each edge: distance, cost, time, capacity. Almost every practical application uses weights, and shortest-path algorithms are built for them.
The handshake theorem
Section titled “The handshake theorem”The sum of all degrees equals twice the number of edges.
Why: every edge has two endpoints, so it contributes exactly 1 to the degree of each, hence 2 to the total. Count the total degree and you’ve counted every edge twice.
The famous consequence:
The number of vertices with odd degree is always even.
Proof sketch: the total degree is even. Split the sum into even-degree vertices and odd-degree vertices. The even part is even, so the odd part must also be even. A sum of odd numbers is even only when there’s an even count of them. ∎
This is why the name “handshake theorem” sticks: at any party, the number of people who shook an odd number of hands is even. And it’s why “can a graph have exactly 3 vertices of odd degree?” always answers no.
Families of graphs
Section titled “Families of graphs”A handful of shapes come up again and again:
- Complete graph - every pair of vertices is adjacent, so each vertex has degree and the edge count is . has 10 edges, matching the group-chat example from the first lesson.
- Cycle graph - vertices in a ring, edges, every vertex of degree 2.
- Path graph - vertices in a line, edges. The two endpoints have degree 1.
- Bipartite graph - the vertices split into two sets with no edges inside either set, so every edge crosses between them. Students and courses, jobs and applicants, actors and films.
- Complete bipartite graph - bipartite with every possible crossing edge present, giving edges.
- Regular graph - every vertex has the same degree. A -regular graph has all degrees equal to . is 2-regular, is -regular.
- Tree - connected with no cycles. Trees get their own lesson.
Subgraphs and complements
Section titled “Subgraphs and complements”A subgraph is a graph formed by taking a subset of the vertices and a subset of the edges among them.
The complement has the same vertices, but an edge exactly where doesn’t. So and together make .
Isomorphism
Section titled “Isomorphism”Two graphs are isomorphic if you can relabel the vertices of one to get the other. They’re structurally the same graph, drawn differently.
Necessary conditions: same number of vertices, same number of edges, same multiset of degrees. Those are quick checks that can prove two graphs are not isomorphic. They aren’t sufficient though, so matching degree sequences doesn’t guarantee isomorphism. Determining isomorphism in general is a notoriously hard computational problem.
Representing a graph
Section titled “Representing a graph”- Adjacency matrix - an grid where entry is 1 if there’s an edge from to and 0 otherwise. For undirected graphs it’s symmetric. Fast to check whether a specific edge exists, but uses space.
- Adjacency list - for each vertex, a list of its neighbors. Compact for sparse graphs, which is most real graphs, and fast to iterate over a vertex’s neighbors.
Real systems almost always use adjacency lists, because a social network with a billion users and a few hundred friends each would need matrix entries to store edges.
Worked Examples
Section titled “Worked Examples”Example 1: Compute degrees and verify the handshake theorem.
and .
Solution.
- (, )
- (, )
- (, , )
- (, )
- ()
Sum: . Edges: 5. And . Confirmed.
Odd-degree vertices: and . That’s 2, an even count, as required.
Example 2: Is this graph possible?
Can a simple graph have 5 vertices with degrees 4, 3, 3, 2, 1?
Solution. Sum the degrees:
That’s odd, but the handshake theorem requires the total degree to be , which is even. Impossible.
Faster check: count the odd degrees. Here 3, 3, and 1 are odd, three of them, an odd count. Impossible.
Example 3: Edges in a complete graph.
How many edges does have? What’s the degree of each vertex?
Solution.
Each vertex connects to the other 11, so .
Verify with the handshake theorem: . Good.
Example 4: Bipartite or not?
Is the cycle bipartite? Is ?
Solution.
has vertices . Split into and . Every edge goes between the two sets, and there’s no edge inside either. Bipartite.
has vertices . Try to 2-color it by alternating: 1 is red, 2 is blue, 3 is red, 4 is blue, 5 is red. But 5 is adjacent to 1, and both are red. Not bipartite.
The general rule: a graph is bipartite if and only if it contains no odd-length cycle. Even cycles alternate perfectly; odd cycles always collide when they close.
Example 5: Degree sequences and isomorphism.
Graph has degree sequence and graph has . Can they be isomorphic?
Solution. No. Isomorphic graphs must have identical degree sequences, and these differ. That’s a complete answer.
But be careful about the reverse. Matching degree sequences do not prove isomorphism. There are non-isomorphic graph pairs with identical degree sequences, so a match only means you have to look harder.
Example 6: Complement.
has 6 vertices and 7 edges. How many edges does have?
Solution. Together they form :
has 8 edges.
Real-World Applications
Section titled “Real-World Applications”Social networks are the most literal application. Users are vertices, connections are edges. Friend recommendation looks for vertices two steps away, community detection finds dense subgraphs, and influence ranking uses degree and centrality measures. “Six degrees of separation” is a claim about path lengths in this graph.
Road and transit networks put intersections at vertices and roads at weighted edges. Every routing app runs shortest-path algorithms over exactly this structure, with weights that update live based on traffic.
The internet itself is a graph at several layers: routers connected by links, and web pages connected by hyperlinks. Google’s original PageRank algorithm ranked pages by analyzing the link graph, treating it as a directed graph and computing which vertices a random walker would visit most.
Dependency graphs are everywhere in software. Package managers, build systems, and task schedulers all model dependencies as directed graphs, and they detect circular dependencies by looking for cycles.
Bipartite graphs handle matching problems: assigning students to schools, doctors to residencies, riders to drivers, or ads to slots. The residency match program that places medical graduates runs a bipartite matching algorithm on a national scale.
Molecules are graphs too, with atoms as vertices and bonds as edges, and chemists use graph isomorphism to identify whether two structural formulas describe the same compound.
Retrying will remove your ✅ checkmark until you pass again.