A graph can be represented in multiple ways.
Diagrammatic Representation
Vertices are denoted by points, edges are denoted by lines. Intuitive. Not practical for big graphs.
Set-theoretic Representation
A graph is represented as an ordered pair where:
- is the set of vertices
- is the set of edges (2-element subsets of for simple graphs; multi-sets for multigraphs)
Adjacency Matrix
An adjacency matrix records how many edges connect each pair of vertices. Shows vertex-vertex relationships.
Suppose a graph has vertices. ’s adjacency matrix representation is defined as:
Where is the number of edges between and .
For undirected graphs, is a symmetric matrix.
For simple graphs:
- entries are 0 or 1
- diagonal entries are 0
If is the adjacency matrix of , entry of is equal to the number of walks of length from to .
Useful for dense graphs (close to the maximum number of edges).
Incidence Matrix
Shows vertex-edge relationships.
For a graph with vertices and edges. Its incidence matrix representation is defined as:
is defined as:
- if vertex is incident with edge and the edge joins two distinct vertices
- if is a loop at
- otherwise
Rows correspond to vertices. Columns correspond to edges.
Useful for edge-based algorithms. Useful for sparse graphs.
For Directed Graphs
Let be an edge from head to tail . Then: