Adjacency List Representation of Graph

We can easily represent graphs using the following ways,

1. Adjacency matrix

2. Adjacency list


In this tutorial, we are going to see how to represent the graph using adjacency list.




Adjacency List

In Adjacency List, we use an array of a list to represent the graph.

The list size is equal to the number of vertex(n).

Let's assume the list of size n as Adjlist[n]

Adjlist[0] will have all the nodes which are connected to vertex 0.

Adjlist[1] will have all the nodes which are connected to vertex 1 and so on.




Undirected Graph

Undirected Graph

Adjacency List of Undirected Graph

Undirected Graph





Directed Graph

Directed Graph

Adjacency List of Directed Graph

Undirected Graph

Topics You Might Like