Adjacency matrix meaning and definition in DSA Last Updated : 09 Jan, 2025 Comments Improve Suggest changes Like Article Like Report An adjacency matrix is a square matrix of N x N size where N is the number of nodes in the graph and it is used to represent the connections between the vertices of a graph.Graph representation of undirected graph to Adjacency MatrixGraph representation of directed graph to Adjacency MatrixCharacteristics of the adjacency matrix are:The size of the matrix is determined by the number of vertices (or nodes) in a graph.The edges in the graph are represented as values in the matrix. In case of unweighted graphs, the values are 0 or 1. In case of weighted graphs, the values are weights of the edges if edges are present, else 0.If the graph has few edges, the matrix will be sparse.How to build an Adjacency Matrix:It is very easy and simple to construct an adjacency matrix for a graph there are certain steps given below that you need to follow:Create an n x n matrix where n is the number of vertices in the graph.Initialize all elements to 0.For each edge (u, v) in the graph, if the graph is undirected mark a[u][v] and a[v][u] as 1, and if the edge is directed from u to v, mark a[u][v] as the 1. (Cells are filled with edge weight if the graph is weighted)Applications of the Adjacency Matrix:Graph algorithms: Many graph algorithms like Floyd-Warshall algorithmImage processing: Adjacency matrices are used in image processing to represent the adjacency relationship between pixels in an image.Finding the shortest path between two nodes: By performing matrix multiplication on the adjacency matrix, one can find the shortest path between any two nodes in a graph. Advantages of using Adjacency Matrix:An adjacency matrix is simple and easy to understand.Adding or removing edges from a graph is quick and easy.It allows constant time access to any edge in the graph.Disadvantages of using Adjacency Matrix:It is inefficient in terms of space utilisation for sparse graphs because it takes up O(N2) space.Computing all neighbors of a vertex takes O(N) time.What else can you read?Kruskal’s Algorithm (Simple Implementation for Adjacency Matrix)Convert Adjacency Matrix to Adjacency List representation of GraphConvert Adjacency List to Adjacency Matrix representation of a GraphComparison between Adjacency List and Adjacency Matrix representation of Graph Comment More infoAdvertise with us Next Article Adjacency matrix meaning and definition in DSA zaidkhan15 Follow Improve Article Tags : Graph DSA Definitions and Meanings Roadmap Practice Tags : Graph Similar Reads Array Definition & Meaning in DSA An array is a collection of items of same data type stored at contiguous memory locations Array exampleTypes of Arrays:One-dimensional Array: It is the simplest kind of array where all the elements are stored linearly in a single row. Two-dimensional Array: A two-dimensional array is an array with 2 4 min read Connected component definition & meaning in DSA Connected component in an undirected graph refers to a group of vertices that are connected to each other through edges, but not connected to other vertices outside the group. For example in the graph shown below, {0, 1, 2} form a connected component and {3, 4} form another connected component. Exam 1 min read Disjoint Set meaning and definition in DSA Disjoint Set is a data structure that keeps track of a set of elements partitioned into a number of disjoint subsets and it is used to efficiently solve problems that involve grouping elements into sets and performing operations on them. Characteristics of the Disjoint Set:It keeps a set partitioned 2 min read Graph definition & meaning in DSA A Graph is a non-linear data structure consisting of vertices and edges where two vertices are connected by an edge. Example of GraphProperties of a Graph:Vertices (nodes): The points where edges meet in a graph are known as vertices or nodes. A vertex can represent a physical object, concept, or ab 4 min read Implementation of DFS using adjacency matrix Depth First Search (DFS) has been discussed in this article which uses adjacency list for the graph representation. In this article, adjacency matrix will be used to represent the graph.Adjacency matrix representation: In adjacency matrix representation of a graph, the matrix mat[][] of size n*n (wh 8 min read Singly Linked List definition & meaning DSA A singly linked list is a special type of linked list in which each node has only one link that points to the next node in the linked list.Singly linked listCharacteristics of a Singly Linked List:Each node holds a single value and a reference to the next node in the list.The list has a head, which 1 min read Graph Representation using Adjacency Matrix in C A graph is a data structure having a set of vertices and a collection of edges that each connect a pair of vertices. There are several ways to represent a graph in computer memory, and one of them is using an adjacency matrix. An adjacency matrix is a 2D array with one row per vertex and one column 4 min read Implementation of BFS using adjacency matrix Breadth First Search (BFS) has been discussed in this article which uses adjacency list for the graph representation. In this article, adjacency matrix will be used to represent the graph.Adjacency matrix representation: In adjacency matrix representation of a graph, the matrix mat[][] of size n*n ( 7 min read Generic Tree meaning & definition in DSA A generic tree (or N-ary Tree) is a type of tree data structure where each node can have at most N number of children where N can be any integer. Example of Generic TreeCharacteristics of Generic Tree:Each node can have zero or more child nodes.A node can have N number of children where N can be any 2 min read Graph Adjacency Matrix in Java A graph is a type of data structure used to represent the relationship between the entities. In this article, we will learn to represent a graph in the form of Adjacency Matrix. Graph Adjacency MatrixThe Adjacency matrix is the way to represent the graphs using the 2D array. It is the fundamental da 6 min read Like