Graphs

Graphs can be used to model problems from virtually any field.

A graph is a pair $(V,E)$ where $V$ is a set called the vertex set and $E$ is a set called the edge set. Each edge in $E$ describes how vertices in $V$ are connected.

Here is an example of a graph:

An example of a graph

This particular graph is a simple graph:

In this graph, edges don't have a direction. We say that the graph is undirected. Therefore, edges can be represented as sets consisting of two vertices. For the above graph,

Sometimes, we might want to allow multiple edges between vertices. Such graphs are called multigraphs:

An example of a multigraph

Edges are still undirected; we can represent them as sets of two vertices. However, now these sets can appear more than once. We say that if there are $m$ distinct edges between $u$ and $v$, the edge $\{u,v\}$ has multiplicity $m$. Multigraphs are used, for example, to model redundant connections in a network.

We might also want to relax the restriction that there are no edges between a vertex and itself. Such edges are called self-loops and a graph that contains self-loops is called a pseudograph. Self-loops model such things as loopbacks in networks.

We can also have directed versions of these graphs, where edges only go in one direction. Here is an example of a directed multigraph:

An example of a directed multigraph

Directed edges can be represented as an ordered pair $(u,v)$ instead of a set $\{u,v\}$. Directed edges model such things as single duplex lines or one-way streets in road networks.

There are many uses of graphs:

Representing Graphs

We need a way of representing graphs if we want to perform operations on them. We could simply list the vertices and edges, but that is a lot of work and it is hard to extract much information from that representation.

Here are two alternatives:

Adjacency and Degree

Let $G = (V,E)$ be a graph.

For example:

Examples of adjacency and degree

The Handshaking Theorem says that, for a graph $G=(V,E)$, we always have $$\sum_{v \in V} \deg(v) = 2|E|$$

For a directed edge $(u,v)$ in a directed graph, $u$ is the initial vertex and $v$ is the terminal vertex or end vertex.

Note that $\sum_{v \in V} \deg^-(v) = \sum_{v \in V} \deg^+(v) = |E|$.

Some Special Graphs

There are a few (types of) graphs with special names:

Subgraphs

A subgraph of a graph $G=(V,E)$ is a graph $H=(W,F)$ such that $W \subseteq V$ and $F \subseteq E$. A subgraph $H$ of $G$ is a proper subgraph of $G$ if $H \neq G$.

For example, on the left we have $K_5$ and on the right is a subgraph of $K_5$.

A graph and a subgraph

A subgraph is spanning if it contains all vertices of the original graph.

Connectivity

Sometimes, we want to know if two vertices in a graph are connected by a sequence of edges that might visit other vertices on the way (for example, can two computers on a network communicate?)

A path is a sequence of edges that begins at a vertex and travels from vertex to vertex along edges of the graph.

More formally, a path of length $n \ge 0$ from vertex $u$ to vertex $v$ in $G$ is a sequence of $n$ edges $e_1,e_2,\ldots,e_n$ of $G$ such that $e_1 = \{ x_0 = u, x_1 \}, e_2 = \{ x_1,x_2 \}, \ldots, e_n = \{x_{n-1},x_n\}$.

For example:

A graph and some paths in it

An undirected graph is connected if there is a path between every two distinct vertices in the graph. For example, the graph on the left is connected but the graph on the right is disconnected.

A connected graph and a disconnected graph

The different parts that are maximally connected are called connected components.

One special type of connected (sub)graph is a tree, which is a connected undirected graph with no simple circuits. For example, the graph on the left is a tree; the graph in the center is not a tree because it contains a circuit; and the graph on the right is not a tree because it is not connected.

Examples of graphs that are and are not trees

Because trees are "simple" in structure, we often want to find a spanning subgraph that is a tree:

An example of a graph and a spanning tree of that graph

In the graph above, the red edges form a spanning subgraph because every vertex appears exactly once. It is a tree because it is connected and contains no circuits.

Returning to subgraphs in general, we note that sometimes removing a single vertex or edge would cause a graph to become disconnected:

For example, consider the following graph:

An example of a graph with cut vertices and edges

The cut vertices are $b,c,e$, and the cut edges are $\{a,b\},\{c,e\}$.

We can also talk about connectivity in directed graphs:

For example, the graph on the left is both strongly and weakly connected, while the graph on the right is only weakly connected since there is no path from $a$ to $b$.

Connectedness in directed graphs