Representations

2 min read Updated Fri Apr 24 2026 07:36:29 GMT+0000 (Coordinated Universal Time)

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 GG is represented as an ordered pair (V,E)(V, E) where:

  • VV is the set of vertices
  • EE is the set of edges (2-element subsets of VV 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 GG has nn vertices. GG’s adjacency matrix representation is defined as:

A(G)=(aij)n×nA(G) = (a_{ij})_{n\times n}

Where aija_{ij} is the number of edges between viv_i and vjv_j.

For undirected graphs, A(G)A(G) 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 GG with nn vertices and mm edges. Its incidence matrix representation is defined as:

I(G)=(aij)n×mI(G) = (a_{ij})_{n\times m}

is defined as:

  • aij=1a_{ij} = 1 if vertex viv_i is incident with edge eje_j and the edge joins two distinct vertices
  • aij=2a_{ij} = 2 if eje_j is a loop at viv_i
  • aij=0a_{ij} = 0 otherwise

Rows correspond to vertices. Columns correspond to edges.

Useful for edge-based algorithms. Useful when the graph is sparse.

For Directed Graphs

Let eje_j be an edge from tail uu to head vv. Then:

  • aij=1a_{ij} = 1 if viv_i is the tail of eje_j
  • aij=1a_{ij} = -1 if viv_i is the head of eje_j
  • aij=2a_{ij} = 2 if eje_j is a loop at viv_i
  • aij=0a_{ij} = 0 otherwise