Representing Graphs Using Matrices: Adjacency and Incidence Matrices
Learn how to represent graphs using matrices—adjacency matrices and incidence matrices. This guide explains how these matrices are constructed for both directed and undirected graphs, providing examples to illustrate these important graph representation techniques.
Representing Graphs Using Matrices
Graphs can be represented using matrices, providing a structured way to store and work with graph data. Two common matrix representations are adjacency matrices and incidence matrices.
Representing Undirected Graphs
1. Adjacency Matrix Representation
For an undirected graph with n vertices, the adjacency matrix is an n x n matrix A = [aij] where:
- aij = 1 if there's an edge between vertices vi and vj.
- aij = 0 if there's no edge between vertices vi and vj.
Note that for an undirected graph, the adjacency matrix is symmetric (aij = aji).
(An example of an undirected graph and its adjacency matrix representation should be included here.)
2. Incidence Matrix Representation
For an undirected graph with n vertices and m edges, the incidence matrix is an n x m matrix C = [cij] where:
- cij = 1 if vertex vi is incident with (connected to) edge ej.
- cij = 0 otherwise.
The sum of the entries in each column is 2 (except for loops, which would contribute 1 to each incident vertex). The total number of 1s in the incidence matrix of an undirected graph (without self-loops) equals twice the number of edges.
(An example of an undirected graph and its incidence matrix representation should be included here.)
Representing Directed Graphs
1. Adjacency Matrix Representation
For a directed graph with n vertices, the adjacency matrix is an n x n matrix A = [aij] where:
- aij = 1 if there's a directed edge from vertex vi to vertex vj.
- aij = 0 otherwise.
The adjacency matrix for a directed graph is not necessarily symmetric.
(An example of a directed graph and its adjacency matrix representation should be included here.)
2. Incidence Matrix Representation
For a directed graph with n vertices and m edges, the incidence matrix is an n x m matrix C = [cij] where:
- cij = 1 if vertex vi is the source of edge ej.
- cij = -1 if vertex vi is the destination of edge ej.
- cij = 0 otherwise.
The total number of 1s in the incidence matrix of a directed graph equals the number of edges in the graph.
(An example of a directed graph and its incidence matrix representation should be included here.)
Representing Multigraphs
Multigraphs (graphs allowing multiple edges between vertices) are typically represented using adjacency matrices. The element aij represents the number of edges between vertices vi and vj.
(An example of a multigraph and its adjacency matrix representation should be included here.)
Conclusion
Adjacency and incidence matrices provide structured ways to represent graphs, enabling efficient storage and manipulation of graph data for various algorithms and analyses.