Open In App

Adjacency List meaning & definition in DSA

Last Updated : 01 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

An adjacency list is a data structure used to represent a graph where each node in the graph stores a list of its neighboring vertices.

Graph representation of Directed Graph to Adjacency List

Characteristics of the Adjacency List:

  • The size of the matrix is determined by the number of nodes in the network.
  • The number of graph edges is easily computed.
  • The adjacency list is a jagged array.

How to build an Adjacency List?

It is very easy and simple to construct an adjacency list for a graph there are certain steps given below that you need to follow:

  • Create an array of linked lists of size N, where N is the number of vertices in the graph.
  • Create a linked list of adjacent vertices for each vertex in the graph.
  • For each edge (u, v) in the graph, add v to the linked list of u, and add u to the linked list of v if the graph is undirected otherwise add v to the list of u if it is directed from u to v. (In case of weighted graphs store the weight along with the connections).

Applications of the Adjacency List:

Advantages of using an Adjacency list:

  • An adjacency list is simple and easy to understand.
  • Adding or removing edges from a graph is quick and easy.

Disadvantages of using an Adjacency list:

  • In adjacency lists accessing the edges can take longer than the adjacency matrix.
  • It requires more memory than the adjacency matrix for dense graphs.

What else can you read?


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads