Open In App

Adjacency List Representation

Last Updated : 07 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
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.

1. Adjacency List for Directed graph:

Consider an Directed and Unweighted graph with 3 vertices and 3 edges. For the graph G, the adjacency list would look like:


C++
#include <iostream>
#include <vector>
using namespace std;

// Function to add an edge between two vertices