Adjacency Matrix for Graphs

Yadavyudhisthir
3 min readDec 9, 2022

--

A matrix with rows and columns called the adjacency matrix, also known as the connection matrix, is used to depict a straightforward labelled graph. This article will discuss adjacency matrices for many kinds of graphs.

A technique for expressing graphs as matrices is adjacency matrix. Finite graphs are described in great detail by the adjacency matrix, which also contributes to their concise representation. There are nodes and edges in a graph. The nodes and edges of a graph are used to characterise the graph in an adjacency matrix. The edges of the network are the finite set of ordered pairs, whereas the nodes are its vertices. The adjacency matrix for graphs, its representation, how to generate an adjacency matrix from a graph, and the adjacency matrix for both directed and undirected graphs will all be covered in this article.

A simple square matrix or connection matrix used to represent a finite graph in matrix form is known as an adjacency matrix. It depicts in a two-dimensional matrix the relationship between the graph’s edges and vertices.

An adjacency matrix of size n x n corresponds to a graph with n vertices or nodes. The number of matrices from one vertex to another is indicated in each matrix entry. Adj [x][y] = w denotes a weighted edge from vertex x to vertex y with a weight of w in a matrix representation of a weighted graph.

If there is an undirected graph G that has n vertices, then the adjacency matrix A will be of n x n size, and if there is an entry in the matrix A = a[i]j], it will be defined as-

How to create an adjacency matrix?

After knowing what the adjacency matrix is and its representation, let’s learn how to create an adjacency matrix from a given graph.

Assume a graph G with n number of a vertex. Then the corresponding adjacency matrix is represented as

The edge is taken to be bi-directional since edges in an undirected graph are assumed to have no directions. It is expected that data can move from node A to node B and vice versa if an edge exists between nodes A and B.

Creating Adjacency matrix for Directed graph

In a directed graph, edges are associated with the directions. Consider the following directed graph and design an adjacency matrix for the corresponding graph.

The edge is taken to be bi-directional since edges in an undirected graph are assumed to have no directions. It is expected that data can move from node A to node B and vice versa if an edge exists between nodes A and B.

Creating Adjacency matrix for Directed graph

In a directed graph, edges are associated with the directions. Consider the following directed graph and design an adjacency matrix for the corresponding graph.

image credits-naukri.com

--

--

Yadavyudhisthir
Yadavyudhisthir

No responses yet