adjacency matrix
Definition
Let $G=(V,E)$ be a graph with vertex set $V=\{{v}_{1},\mathrm{\dots},{v}_{n}\}$ and edge set $E$. The adjacency matrix^{} ${M}_{G}=({m}_{ij})$ of $G$ is defined as follows: ${M}_{G}$ is an $n\times n$ matrix such that
$${m}_{ij}=\{\begin{array}{cc}1\hfill & \text{if}\{{v}_{i},{v}_{j}\}\in E\hfill \\ 0\hfill & \text{otherwise.}\hfill \end{array}$$ 
In other words, start with the $n\times n$ zero matrix^{}, put a $1$ in $(i,j)$ if there is an edge whose endpoints^{} are ${v}_{i}$ and ${v}_{j}$.
For example, the adjacency matrix of the following graph
is
$$\left(\begin{array}{ccccc}\hfill 0\hfill & \hfill 0\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 0\hfill \\ \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 0\hfill & \hfill 0\hfill & \hfill 0\hfill \\ \hfill 0\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 0\hfill & \hfill 0\hfill \end{array}\right).$$ 
Remarks. Let $G$ be a graph and ${M}_{G}$ be its adjacency matrix.

•
${M}_{G}$ is symmetric^{} with $0$’s in its main diagonal.

•
The sum of the cells in any given column (or row) is the degree of the corresponding vertex. Therefore, the sum of all the cells in ${M}_{G}$ is twice the number of edges in $G$.

•
${M}_{G}=\mathrm{\U0001d7cf}I$ iff $G$ is a complete graph^{}. Here, $\mathrm{\U0001d7cf}$ is the matrix whose entries are all $1$ and $I$ is the identity matrix^{}.

•
If we are given a symmetric matrix $M$ of order $n$ whose entries are either $1$ or $0$ and whose entries in the main diagonal are all $0$, then we can construct a graph $G$ such that $M={M}_{G}$.
Generalizations
The above definition of an adjacency matrix can be extended to multigraphs^{} (multiple edges between pairs of vertices allowed), pseudographs^{} (loops allowed), and even directed pseudographs (edges are directional). There are two cases in which we can generalize the definition, depending on whether edges are directional.

1.
(Edges are not directional).
Since a multigraph is just a special case of a pseudograph, we will define ${M}_{G}$ for a pseudograph $G$. Let $G=(V,E)$ be a pseudograph with $V=\{{v}_{1},\mathrm{\dots},{v}_{n}\}$ The adjacency matrix ${M}_{G}=({m}_{ij})$ of $G$ is an $n\times n$ matrix such that ${m}_{ij}$ is the number of edges whose endpoints are ${v}_{i}$ and ${v}_{j}$. Again, ${M}_{G}$ is symmetric, but the main diagonal may contain nonzero entries, in case there are loops.

2.
(Edges are directional).
Since a digraph^{} is a special case of a directed pseudograph, we again define ${M}_{G}$ in the most general setting. Let $G=(V,E)$ be a directed pseudograph with $V=\{{v}_{1},\mathrm{\dots},{v}_{n}\}$ and $E\subseteq V\times V\times (\mathbb{N}\cup \{0\})$. The adjacency matrix ${M}_{G}$ of $G$ is an $n\times n$ matrix such that
$${m}_{ij}=\{k\mid ({v}_{i},{v}_{j},k)\in E\}.$$ In other words, ${m}_{ij}$ is the number of directed edges from ${v}_{i}$ to ${v}_{j}$.
Remarks

•
If $G$ is a multigraph, then the entries in the main diagonal of ${M}_{G}$ must be all $0$.

•
If $G$ is a graph, then ${M}_{G}$ corresponds to the original definition given in the previous section^{}.

•
If $G$ is a digraph, then entries ${M}_{G}$ consists of $0$’s and $1$’s and its main diagonal consists of all $0$’s.

•
Given any square matrix^{} $M$, there is a directed pseudograph $G$ with $M={M}_{G}$. In addition^{}, $M$ corresponds to adjacency matrix of various types of graphs if appropriate conditions are imposed on $M$

•
Generally, one can derive a pseudograph from a directed pseudograph by “forgetting” the order in the ordered pairs of vertices. If $G$ is a directed pseudograph and ${G}^{\prime}$ is the corresponding derived pseudograph. Let ${M}_{G}=({m}_{ij})$ and ${M}_{{G}^{\prime}}=({n}_{ij})$, then ${n}_{ij}={m}_{ij}+{m}_{ji}$.
In the language^{} of category theory^{}, the above operation^{} is done via a forgetful functor^{} (from the category^{} of directed pseudographs to the category of pseudographs). Other forgetful functors between categories of various types of graphs are possible. In each case, the forgetful functor has an associated operation on the adjacency matrices of the graphs involved.
Title  adjacency matrix 

Canonical name  AdjacencyMatrix 
Date of creation  20130322 17:22:43 
Last modified on  20130322 17:22:43 
Owner  CWoo (3771) 
Last modified by  CWoo (3771) 
Numerical id  7 
Author  CWoo (3771) 
Entry type  Definition 
Classification  msc 05C50 