Adjacency Matrix
In the adjacency matrix representation of a graph, a Boolean matrix contains a 1 in position (i,j) iff there is a link from vi to vj, otherwise 0.
1 | 2 | 3 | 4 | 5 | 6 | |
1 | 0 | 1 | 0 | 0 | 1 | 0 |
2 | 1 | 0 | 1 | 0 | 1 | 0 |
3 | 0 | 1 | 0 | 1 | 0 | 0 |
4 | 0 | 0 | 1 | 0 | 1 | 1 |
5 | 1 | 1 | 0 | 1 | 0 | 0 |
6 | 0 | 0 | 0 | 1 | 0 | 0 |
Since this graph is undirected, each link is represented twice, and the matrix is symmetric.
The storage required is O(|V|2); even though only one bit is used for each entry, the storage can be excessive.