No history yet

Introduction to Graph Theory

What is a Graph?

Think of a social network. You have people, and you have the friendships connecting them. Or imagine a map of cities linked by roads. Both are perfect examples of graphs.

In mathematics, a graph is just a way to represent connections. It's made of two simple things: dots and lines.

vertex

noun

A fundamental unit of a graph, often represented as a dot or circle. It's also called a node.

edge

noun

A connection between two vertices, typically drawn as a line. It's also called a link or arc.

That's it. A graph is just a collection of vertices and the edges that connect them. This simple structure can model almost any network, from the internet to the neurons in your brain.

Types of Graphs

Not all connections are the same. A friendship on Facebook is mutual, but following someone on Instagram is a one-way street. Graphs can capture these differences.

An undirected graph has edges that go both ways. If A is connected to B, then B is connected to A. It's a two-way relationship, like a friendship or a telephone call.

A directed graph, or digraph, has edges with a specific direction, shown with an arrow. If A points to B, it doesn't mean B points back to A. This is perfect for modeling one-way links, like a car on a one-way street or a follower on social media.

Edges can also carry more information. An unweighted graph just shows that a connection exists. The edges are all or nothing.

A weighted graph assigns a value, or "weight," to each edge. This weight can represent anything: distance, time, cost, or the strength of a connection. A map of airline routes is a weighted graph, where each edge's weight could be the flight time or ticket price.

Finding Your Way Around

Once you have a graph, you can start exploring it. A path is a sequence of vertices where each vertex is connected to the next by an edge. Think of it as a route from a starting point to a destination.

A cycle is a special kind of path that starts and ends at the same vertex. It's a round trip. In the flight map above, Dallas -> New York -> Chicago -> Dallas forms a cycle.

These ideas lead to the concept of connectivity. An undirected graph is connected if there is a path between every pair of vertices. If not, the graph is disconnected and consists of separate "components." It's like an island nation—some islands might be connected by bridges, while others are isolated.

Storing Graphs

To work with graphs in a computer, we need a systematic way to store them. Two common methods are adjacency matrices and adjacency lists.

An adjacency matrix is a grid, or a table, where both rows and columns represent the vertices of the graph. A cell at row i and column j contains a 1 if there's an edge from vertex i to vertex j, and a 0 otherwise. For weighted graphs, the cell stores the edge's weight instead of a 1.

Lesson image

Adjacency matrices are simple and fast for checking if an edge exists between two specific vertices. However, they can use a lot of memory for graphs with many vertices but few edges, since most of the grid would be filled with zeros.

An adjacency list is more memory-efficient for sparse graphs. It's a list where each item corresponds to a vertex. That item then holds another list containing all the vertices it's connected to.

For a graph with vertices A, B, and C, where A is connected to B and C, and B is also connected to C, the adjacency list would look like: A: [B, C] B: [A, C] C: [A, B]

Here's how the two methods compare for a simple undirected, unweighted graph:

MethodRepresentationPros & Cons
Adjacency Matrix A B C D
A [0,1,1,0]
B [1,0,0,1]
C [1,0,0,1]
D [0,1,1,0]
Fast to check a specific edge. Uses more space for sparse graphs.
Adjacency ListA: [B, C]
B: [A, D]
C: [A, D]
D: [B, C]
Space-efficient for sparse graphs. Slower to check a specific edge.

Choosing the right representation depends on the graph's structure and what you plan to do with it. Both are foundational tools for working with graph data.

Quiz Questions 1/6

What are the two fundamental components that make up a graph in mathematics?

Quiz Questions 2/6

You are modeling a social network where 'following' someone doesn't automatically mean they follow you back. Which type of graph is most appropriate for this scenario?

These fundamental concepts—vertices, edges, types, and representations—are the building blocks for exploring the powerful world of graphs.