05. Print adjacency list
The problem can be found at the following link: Question Link
My Approach
A basic question with a direct approach:
I'm creating an adjacency list of a 2D vector to represent the graph.
I iterate through the given edges and
push
them to the adjacency list, ensuring to push vertices from both directions since it's an undirected graph.
Time and Auxiliary Space Complexity
Time Complexity :
O(E)
, whereE
is the number of edges in the graph.Auxiliary Space Complexity :
O(V + E)
, whereV
is the number of vertices andE
is the number of edges.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.
Last updated