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
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 when the graph is sparse.
For Directed Graphs
Let be an edge from tail to head . Then:
- if is the tail of
- if is the head of
- if is a loop at
- otherwise