2 Dec 2019

  • December 02, 2019
  • Amitraj
Adjacency Matrix

1. Adjacency matrix is a way to represent a graph.
2. It shows which nodes are adjacent to one another.
3. Graph is represented using a square matrix.

Graph can be divided into two categories:
a. Sparse Graph
b. Dense Graph


a. Sparse graph contains less number of edges.

b. Dense graph contains number of edges as compared to sparse graph.

->Adjacency matrix is best for dense graph, but for sparse graph, it is not required.

->Adjacency matrix is good solution for dense graph which implies having constant number of vertices.


NOTE: Adjacency matrix of an undirected graph is always a symmetric matrix which means an edge (i, j) implies the edge (j, i).


NOTE: Adjacency matrix of a directed graph is never symmetric adj[i][j] = 1, indicated a directed edge from vertex i to vertex j.




Advantages of Adjacency Matrix

1. Adjacency matrix representation of graph is very simple to implement.

2. Adding or removing time of an edge can be done in O(1) time. 

3. Same time is required to check, if there is an edge between two vertices.

4. It is very convenient and simple to program.



Disadvantages of Adjacency Matrix

1. It consumes huge amount of memory for storing big graphs.

2. It requires huge efforts for adding or removing a vertex. If you are constructing a graph in dynamic structure, adjacency matrix is quite slow for big graphs.

Related Posts:

  • Singly Linked List Data Structure Singly Linked List Data Structure -> Singly linked lists contain nodes which have a data part as well as an address part i.e. next, which points to the next node in the sequence of nodes. -> Operations that can be p… Read More
  • Tree (data Structure) | Tree Terminology Tree (data Structure) -> In linear data structure data is organized in sequential order and in non-linear data structure data is organized in Random order. -> A tree is a very popular non-linear data structure used i… Read More
  • Difference between Array and Linked List Difference between Array and Linked List -> Both Linked List and Array are used to store linear data of similar type, but an array consumes contiguous memory locations allocated at compile time, i.e. at the time of decl… Read More
  • infix to post fix (Reverse polish notation) expression Infix Expression It follows the scheme of <operand><operator><operand> i.e. an <operator> is preceded and succeeded by an <operand>. Such an expression is termed infix expression. E… Read More
  • Doubly Linked List Data Structure  Doubly Linked List Data Structure -> Doubly Linked List is a variation of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List.  -&g… Read More

Translate

Popular Posts