Table of Contents
What is Adjacency Matrix?
Adjacency Matrix – Definition: An adjacency matrix is a mathematical matrix used to represent a graph. It has an entry in each row and column for each vertex in the graph. The entry in the ith row and jth column is 1 if there is an edge from vertex i to vertex j, and 0 otherwise.
Following are the Key Properties of an Adjacency Matrix:
- An adjacency matrix is a square matrix that contains a binary (0 or 1) value in each entry, representing whether or not two vertices are adjacent.
- The diagonal of the adjacency matrix is all 1s, since every vertex is adjacent to itself.
- The adjacency matrix is symmetric, meaning that the matrix is the same if you swap the rows and columns.
- The adjacency matrix is also directed, meaning that the direction of the edge matters. For example, in a graph with edges (A,B) and (B,C), the adjacency matrix would have a 1 in the row for A and the column for B, and a 1 in the row for B and the column for C.
How to create an Adjacency Matrix?
An adjacency matrix is a square matrix that contains a boolean value (true or false) in each element, where the element represents whether or not two vertices are adjacent.
Properties of Adjacent Matrix –
Matrix and Vector
A matrix an array of numbers arranged in rows and columns. A vector is a one-dimensional array of numbers.
The matrix and vector have the following properties:
- matrix is two-dimensional, while the vector is one-dimensional.
- The matrix has a number of rows and columns, while the vector has a number of elements.
- matrix is rectangular, while the vector is linear.
- The matrix is static, while the vector is dynamic.
- matrix fixed, while the vector is variable.
Adjacency Matrix of an Undirected Graph-
A graph is a collection of points, called vertices, and the lines connecting them, called edges.
Adjacency Matrix of a Directed Graph
The adjacency matrix of a directed graph is a square matrix, where the i-th row and column represent the vertices of the graph, and the entry in the i-th row and column is 1 if there is an edge from vertex i to vertex j, and 0 otherwise.
The adjacency matrix for a directed graph can computed using the following algorithm:
Algorithm: Adjacency Matrix for a Directed Graph
- Create a square matrix, where the i-th row and column represent the vertices of the graph, and the entry in the i-th row and column is 1 if there is an edge from vertex i to vertex j, and 0 otherwise.
- Set all entries in the matrix to 0.
- For each i and j, set the entry in the i-th row and column to 1 if there is an edge from vertex i to vertex j, and 0 otherwise.
Questions to Solved-
- How much water flows through the Hoover Dam in a year?
- How many turbines are at the Hoover Dam?
- What is the maximum capacity of the Hoover Dam?