Representations

2 min read Last updated Wed May 27 2026 01:45:12 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

If AA is the adjacency matrix of GG, entry (i,j)(i, j) of AmA^m is equal to the number of walks of length mm from viv_i to vjv_j.

Useful for dense graphs (close to the maximum number of edges).

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 for sparse graphs.

For Directed Graphs

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

aij={1if vi is the tail of ej1if vi is the head of ej2if ej is a loop at vi0otherwisea_{ij} = \begin{cases} 1 & \text{if } v_i \text{ is the tail of } e_j \\ -1 & \text{if } v_i \text{ is the head of } e_j \\ 2 & \text{if } e_j \text{ is a loop at } v_i \\ 0 & \text{otherwise} \end{cases}
Was this helpful?