Adjacency Matrix Representation of Graph
We can easily represent the graphs using the following ways,
1. Adjacency matrix
2. Adjacency list
In this tutorial, we are going to see how to represent the graph using adjacency matrix.
If a graph has n vertices, we use n x n matrix to represent the graph.
Let's assume the n x n matrix as adj[n][n].
if there is an edge from vertex i to j, mark adj[i][j] as 1. i.e. adj[i][j] == 1
if there is no edge from vertex i to j, mark adj[i][j] as 0. i.e. adj[i][j] == 0
Adjacency Matrix of Undirected Graph
Adjacency Matrix of Directed Graph