152. Undirected graphs
In Chapters 144 through 151, we considered digraphs that consisted of nodes and arrows between some of the nodes. The graphs considered in this section have nodes with edges between them, but the edges have no direction assigned to them.
152.1 Definition: graph
A graph $G$ consists of two finite sets $G_{0}$ and $G_{1}$ together with a function $\Gamma$ from $G_{1}$ to the set of two-element subsets of $G_{0}$. The elements of $G_{0}$ are called nodes or xvertices of $G$ and the elements of $G_{1}$ are called edges.

152.2 Definition: simple graph
$G$ is a simple graph if $\Gamma$ is injective, so that there is no more than one edge connecting two nodes.
152.2.1 Exercise Which of the graphs in Table (152.1) are simple? (Answer on page 251.)
152.2.2 Remark We will sometimes use the word “multigraph” to emphasize that we are talking about a graph that is not necessarily simple.
152.2.3 Drawing graphs One draws a graph by using dots for the nodes, and drawing a line between nodes $p$ and $q$ for each edge $e$ for which $\Gamma(e)=\{p,q\}$. In common with most of the literature on the subject, our graphs do not have loops: the requirement that $\Gamma$ have values in the set of two-element subsets rules out the possibility of loops.
152.2.4 Example The figure below shows two graphs; the one on the right is simple.

In the left graph the set of nodes is $\{q,r,s,t\}$, the set of edges is $\{a,b,u,v,x,w,y\}$, and, for example, $\Gamma(a)=\{r,t\}$.
152.3 Definition: incidence
If $e$ is an edge in a graph and $\Gamma(e)=\{p,q\}$ then $e$ is said to be incident on $p$ (and on $q$). Two nodes connected by an edge in a simple graph are adjacent. If $n$ edges connect two nodes the nodes are said to be adjacent with multiplicity $n$.
152.4 Definition: adjacency matrix
The adjacency matrix of a graph is the square matrix $A$ whose rows and columns are indexed by the set of nodes, with $A(p,q)=$the number of edges between $p$ and $q$.
152.4.1 Fact It follows from the definition that for any (multi)graph with adjacency matrix $A$,
(i) for any node $p$, $A(p,p)=0$;
(ii) for any nodes $p$ and $q$, $A(p,q)=A(q,p)$ (this says $A$ is symmetric); and
(iii) if the graph is simple, $A$ has only 0’s and 1’s as entries.
152.4.2 Remark Because of 152.4.1(i) and (ii), all the information about the graph is contained in the triangular matrix consisting of the entries $A(p,q)$ with $p<q$.
152.4.3 Example The adjacency matrix of the left graph in Figure (152.1) is
$$\begin{array}{c|cccc} & r & q & t & s \\ \hline r & 0 & 1 & 2 & 0 \\ q & 1 & 0 & 1 & 1 \\ t & 2 & 1 & 0 & 2 \\ s & 0 & 1 & 2 & 0 \end{array}$$
152.5 Definition: degree
The degree of node is the number of edges incident on that node.
152.5.1 Example The degree of the node $c$ in the right graph in Figure (152.1), page 232, is 3, and the degree of $d$ is 1.
152.5.2 Fact The degree of a node is the sum over the row (and also over the column) of the adjacency matrix corresponding to that node.
152.5.3 Exercise Show that the sum of the degrees of the nodes of a graph is twice the number of edges.
Pages 230–233 of the book (PDF).