Adjacency matrix Guide, Meaning , Facts, Information and Description
In mathematics and computer science, the adjacency matrix for a finite graph is a (0,1)-matrix representation of the graph. An alternative matrix representation for a graph is the incidence matrix.For sparse graphs, that is graphs with few edges, an adjacency list is often the preferred representation because it uses less space.
The relationship between a graph and its adjacency matrix is studied in Spectral graph theory.
| Table of contents |
|
2 Examples 3 Properties 4 Trade-offs as a data structure |
The adjacency matrix of a directed or undirected graph G with n vertices is the n-by-n matrix M with
The adjacency matrix for the example graph
The adjacency matrix of an undirected graph is symmetric, and therefore has a complete set of eigenvalues and orthogonal eigenvector basis. The eigenvalues of a graph are the Spectrum of the Graph.
Suppose two directed or undirected graphs G1 and G2 with adjacency matrices A1 and A2 are given. G1 and G2 are isomorphic if and only if there exists a permutation matrix P such that
If A is the adjacency matrix of the directed or undirected graph G, then the matrix An (i.e. the matrix product of n copies of A) has an interesting interpretation: the entry in row i and column j gives the number of (directed or undirected) paths of length n from vertex i to vertex j.
The matrix I−A (where I denotes the n-by-n identity matrix) is invertible if and only if there are no directed cycles in the graph G. In this case, the inverse (I−A)−1 has the following interpretation: the entry in row i and column j gives the number of directed paths from vertex i to vertex j (which is always finite if there are no directed cycles). This can be understood using the geometric series for matrices:
When used as a data structure, the main competitor for the adjacency matrix is the adjacency list. Because each entry in the adjacency matrix requires only one bit, they can be represented in a very compact way, occupying only n2/8 bytes of contiguous space, where n is the number of vertices. Besides just avoiding wasted space, this compactness encourages locality of reference.
On the other hand, for a sparse graph, adjacency lists win out, because they do not use any space to represent edges which are not present. Using a naive linked list implementation on a 32-bit computer, an adjacency list for an undirected graph requires about 16e bytes of storage, where e is the number of edges.
Noting that a simple graph can have at most n2 edges, allowing loops, we can let d = e/n2 denote the density of the graph. Then, 16e > n2/8, or the adjacency list representation occupies more space, precisely when d > 1/128. Thus a graph must be sparse indeed to justify an adjacency list representation.
Besides the space tradeoff, the different data structures also facilitate different operations. It's easy to find all vertices adjacent to a given vertex in an adjacency list representation; you simply read its adjacency list. With an adjacency matrix you must instead scan over an entire row, taking O(n) time. If you, instead, want to know if two given vertices have an edge between them, this can be determined at once with an adjacency matrix, while requiring time proportional to the minimum degree of the two vertices with the adjacency list.
This is an Article on Adjacency matrix. Page Contains Information, Facts Details or Explanation Guide About Adjacency matrix Definition
with E(G) the edge set of G. In other words the entry in row i and column j is one if there is an edge in the graph with the i-th vertex as source and the j-th vertex as target. Examples
is
Properties
In particular, A1 and A2 are similar and have therefore the same minimal polynomial, characteristic polynomial, eigenvalues, determinant and trace. These can therefore serve as isomorphism invariants of graphs. The multiplication with the permutation matrix can be visualized as a relabeling of the vertices.
corresponding to the fact that the number of paths from i to j equals the number of paths of length 0 plus the number of paths of length 1 plus the number of paths of length 2 etc.Trade-offs as a data structure
