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?


Similar Reads

Adjacency matrix meaning and definition in DSA
An adjacency matrix is a square matrix of N x N size where N is the number of nodes in the graph and it is used to represent the connections between the edges of a graph. Characteristics of the adjacency matrix are:The size of the matrix is determined by the number of vertices in the graph.The number of nodes in the graph determines the size of the
2 min read
Convert Adjacency Matrix to Adjacency List representation of Graph
Prerequisite: Graph and its representations Given a adjacency matrix representation of a Graph. The task is to convert the given Adjacency Matrix to Adjacency List representation. Examples: Input: arr[][] = [ [0, 0, 1], [0, 0, 1], [1, 1, 0] ] Output: The adjacency list is: 0 -> 2 1 -> 2 2 -> 0 -> 1Input: arr[][] = [ [0, 1, 0, 0, 1], [1,
6 min read
Comparison between Adjacency List and Adjacency Matrix representation of Graph
A Graph is a non-linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. In this article, we will understand the difference between the ways of representation of the graph. A graph can be represented in mainly two ways. They ar
4 min read
Convert Adjacency List to Adjacency Matrix representation of a Graph
Given an adjacency list representation of a Graph, the task is to convert the given Adjacency List to Adjacency Matrix representation. Examples: Input: adjList[] = {{0 --> 1 --> 3}, {1 --> 2}, {2 --> 3}} Output: 0 1 0 10 0 1 00 0 0 10 0 0 0 Input: adjList[] = {{0 --> 1 --> 4}, {1 --> 0 --> 2 --> 3 --> 4}, {2 --> 1 -
9 min read
Singly Linked List definition & meaning DSA
A singly linked list is a special type of linked list in which each node has only one link that points to the next node in the linked list. Characteristics of a Singly Linked List:Each node holds a single value and a reference to the next node in the list.The list has a head, which is a reference to the first node in the list, and a tail, which is
3 min read
Disjoint Set meaning and definition in DSA
Disjoint Set is a data structure that keeps track of a set of elements partitioned into a number of disjoint subsets and it is used to efficiently solve problems that involve grouping elements into sets and performing operations on them. Characteristics of the Disjoint Set:It keeps a set partitioned into disjoint subsets.It allows the efficient uni
2 min read
Balanced Binary Tree definition & meaning in DSA
Balanced binary tree is defined as a binary tree data structure where there is no more than one height difference between the left and right subtrees of any given node. Mathematically Height of left subtree - Height of right subtree ≤1 Properties of Balanced Binary Tree: A balanced binary tree has a height that is logarithmic in the number of nodes
2 min read
Array Definition & Meaning in DSA
An array is a collection of items of same data type stored at contiguous memory locations Types of Arrays:One-dimensional Array: It is the simplest kind of array where all the elements are stored linearly in a single row. Two-dimensional Array: A two-dimensional array is an array with 2 dimensions, i.e., each unique element is accessed using two it
4 min read
Stack Definition & Meaning in DSA
A stack is defined as a linear data structure that is open at one end and the operations follow the Last-In-First-Out (LIFO) order. Characteristics of Stack:The stack follows the LIFO order, which means that the last element added to the stack will be the first element to be removed.A register that points to the top of the stack is known as the sta
2 min read
What is Tree | Tree Definition & Meaning in DSA
A tree is defined as a hierarchical data structure in which the elements (known as nodes) are linked together via edges such that there is only one path between any two node of the tree. Properties of Trees:Number of edges: An edge can be defined as the connection between two nodes. If a tree has N nodes then it will have (N-1) edges.Depth of a nod
4 min read
Practice Tags :
three90RightbarBannerImg