# Representation of Graphs

MathematicsComputer EngineeringMCA

#### Mathematics for Data Science and Machine Learning using R

64 Lectures 10.5 hours

#### Engineering Mathematics - Numerical Analysis & more

6 Lectures 1 hours

#### Advanced Mathematics Preparation for JEE/CET/CAT

30 Lectures 3.5 hours

There are mainly two ways to represent a graph −

An Adjacency Matrix A[V][V] is a 2D array of size V × V where $V$ is the number of vertices in a undirected graph. If there is an edge between Vx to Vy then the value of A[Vx][Vy]=1 and A[Vy][Vx]=1, otherwise the value will be zero. And for a directed graph, if there is an edge between Vx to Vy, then the value of A[Vx][Vy]=1, otherwise the value will be zero.

Adjacency Matrix of an Undirected Graph

Let us consider the following undirected graph and construct the adjacency matrix −

The adjacency matrix of the above-undirected graph will be −

 a b c d a 0 1 1 0 b 1 0 1 0 c 1 1 0 1 d 0 0 1 0

Adjacency Matrix of a Directed Graph

Let us consider the following directed graph and construct its adjacency matrix −

The adjacency matrix of the above-directed graph will be −

 a b c d a 0 1 1 0 b 0 0 1 0 c 0 0 0 1 d 0 0 0 0