Write a C Program for Creation of Adjacency Matrix

By | May 11, 2017

Creation of Adjacency Matrix


Write a C Program for Creation of Adjacency Matrix. Here’s simple Program for adjacency matrix representation of graph in data structure in C Programming Language.


Adjacency Matrix: 


Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph. Let the 2D array be adj[][], a slot adj[i][j] = 1 indicates that there is an edge from vertex i to vertex j.

Adjacency matrix for undirected graph is always symmetric. Adjacency Matrix is also used to represent weighted graphs. If adj[i][j] = w, then there is an edge from vertex i to vertex j with weight w.

Pros: Representation is easier to implement and follow. Removing an edge takes O(1) time. Queries like whether there is an edge from vertex ‘u’ to vertex ‘v’ are efficient and can be done O(1).

Cons: Consumes more space O(V^2). Even if the graph is sparse(contains less number of edges), it consumes the same space. Adding a vertex is O(V^2) time.


Check Out : : How to Print Spiral Order Traversal of a Binary Tree

Below is the source code for C Program for Creation of Adjacency Matrix which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post…


Recommended Posts : :

2 thoughts on “Write a C Program for Creation of Adjacency Matrix

  1. Pingback: Insert Delete Edges in a Directed graph using Adjacency Matrix

  2. Pingback: C Program to implement BFS Algorithm for Disconnected Graph

Leave a Reply