Graphs can be represented by
- Adjacency Matrix by Sequential Representation
- Linked Representation by using an adjacency list that stores neighbors of a node using linked list.
- It represents which nodes are adjacent to each other i.e. which nodes have edge connecting between them.
- Rows and Columns are labeled by graph vertices.
- a is the adjacency matrix,i represents row, j represents column,v i and vj represents vertices.
- aij is 1 if v i and vj are adjacent to each other and 0 if they are not.
- Adjacency Matrix is also known as Bit matrix or Boolean Matrix since it contains only o's and 1's.
The graph is shown in Fig 1 and matrix is shown in Fig 2.
The graph is shown in Fig 3 and matrix is shown in Fig 4.
The graph is shown in Fig 5 and matrix is shown in Fig 6.
It is an another way to represent graphs in computer memory.It is a linked representation in which every node is linked to its own list that contains he names of all other nodes which are adjacent to itself.The graph is shown in Fig 7 and list is shown in Fig 8.
Advantages of Adjacency List
- It clearly shows the adjacent nodes of a particular node.
- Adding new nodes in the list is easy as compared to adding nodes in the adjacency matrix.