The perfect place for easy learning...

Data Structures

×

Topics List

Place your ad here

Graph Representations

Graph data structure is represented using following representations...

  1. Adjacency Matrix
  2. Incidence Matrix
  3. Adjacency List

Adjacency Matrix

In this representation, graph is represented using a matrix of size total number of vertices by total number of vertices. That means graph with 4 vertices is represented using a matrix of size 4X4. In this matrix, both rows and columns represents vertices. This matrix is filled with either 1 or 0. Here, 1 represents that there is a edge from row vertex to column vertex and 0 represents that there is no edge from row vertex to column vertex.

For example, consider the following undirected graph representation...

adjacency matrix representation

Directed graph representation...

adjacency matrix representation

Incidence Matrix

In this representation, graph is represented using a matrix of size total number of vertices by total number of edges. That means graph with 4 vertices and 6 edges is represented using a matrix of size 4X6. In this matrix, rows represents vertices and columns represents edges. This matrix is filled with 0 or 1 or -1. Here, 0 represents that the row edge is not connected to column vertex, 1 represents that the row edge is connected as outgoing edge to column vertex and -1 represents that the row edge is connected as incoming edge to column vertex.

For example, consider the following directed graph representation...

incidence matrix representation

Adjacency List

In this representation, every vertex of a graph contains list of its adjacent vertices.

For example, consider the following directed graph representation implemented using linked list...

adjacency list representation

This representation can also be implemented using array as follows..


Place your ad here
Place your ad here