Adjacency List Representation

But found it inefficient when our graph consists of a huge number of vertices.
Adjacency list representation. Each edge in the network is indicated by listing the pair of nodes that are connected. The adjacency list representation of a graph is linked list representation. There are many variations of this basic idea differing in the details of how they implement the association between vertices and collections in how they implement the collections in whether they include both vertices and edges or only vertices as first class objects and in what kinds of objects are used to represent the vertices and edges. An adjacency list represents a graph as an array of linked lists.
Let the array be an array. An entry array i represents the list of vertices adjacent to the ith vertex. In this representation we have an array of lists the array size is v. An adjacency list also called an edge list is one of the most basic and frequently used representations of a network.
An adjacency list representation for a graph associates each vertex in the graph with the collection of its neighboring vertices or edges. Here we store the adjacent vertices of a given vertex as a list. Degree of a node in an undirected graph is given by the length of the corresponding linked list. In the last post we used a 2d matrix to represent the graph.
Here v is the number of vertices. Overhead of maintaining pointers adjacency list representation does not remain cost effective over adjacency matrix representation of a graph. The weights can also be stored in the linked list node. In other words we can say that we have an array to store v number of different lists.
Each element of array is a list of corresponding neighbour or directly connected vertices in other words ith list of adjacency list is a list of all those vertices which is directly connected to ith vertex. Please see this for a sample python implementation of adjacency matrix. Each list describes the set of neighbors of its vertex. Now adjacency list is an array of seperate lists.
The index of the array represents a vertex and each element in its linked list represents the other vertices that form an edge with the vertex. Tom hanks bill paxton. Adjacency list is the array of linked list where array size is same as number of vertices in the graph. Another way to represent graph is using adjacency list.
This representation can also be used to represent a weighted graph. The size of the array is equal to the number of vertices. For example the adjacency list for the apollo 13 network is as follows. Every vertex has a linked list.
Each node in this linked list represents the reference to the other vertices which share an edge with the current vertex. See storing a sparse matrix for an alternative approach.