data structures using if otherwise the path matrix is used to show whether there exists simple path from node vi to vj or not this is shown in fig let us now calculate matrix and matrix using the above discussion [if there is path from vi to vjpij [otherwisefigure path matrix entry ii ii ii ii now the path matrix can be given ase adjacency list representation an adjacency list is another way in which graphs can be represented in the computer' memory this structure consists of list of all nodes in furthermoreevery node is in turn linked to its own list that contains the names of all other nodes that are adjacent to it the key advantages of using an adjacency list areit is easy to follow and clearly shows the adjacent nodes of particular node it is often used for storing graphs that have small-to-moderate number of edges that isan adjacency list is preferred for representing sparse graphs in the computer' memoryotherwisean adjacency matrix is good choice adding new nodes in is easy and straightforward when is represented using an adjacency list adding new nodes in an adjacency matrix is difficult taskas the size of the matrix needs to figure graph and its adjacency list be changed and existing nodes may have to be reordered consider the graph given in fig and see how its adjacency list is stored in the memory for directed graphthe sum of the lengths of all adjacency lists is equal to the number of edges in (undirected graphg howeverfor an undirected graphthe sum of the lengths of all adjacency lists is equal to twice the number of edges in because an edge (uvmeans an edge from node to as well as an edge from adjacency lists can also be modified to store to (weighted graphweighted graphs let us now see an adjacency list figure adjacency list for an undirected graph for an undirected graph as well as weighted graph and weighted graph this is shown in fig