...

/

AdjacencyMatrix: Representing a Graph by a Matrix

AdjacencyMatrix: Representing a Graph by a Matrix

Learn about the representation of graphs by matrices.

An adjacency matrix is a way of representing an nn vertex graph G=(V,E)G = (V ,E) by an n×nn \times n matrix, a, whose entries are boolean values.

Press + to interact
int n;
boolean[][] a;
AdjacencyMatrix(int n0) {
n = n0;
a = new boolean[n][n];
}

The matrix entry a[i][j] is defined as

a[i][j]={true   if (i,j)Efalse   otherwise a[i][j] = \begin{cases} true & \ \ \ \text{if $(i,j)\in E$} \\ false & \ \ \ \text{otherwise} \end{cases}\ ...