Python Coding Practice

Solve Print Adjacency List using Python Language

Solve Print Adjacency List using Python to enhance your skills with python coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Print Adjacency List

Difficulty : Easy

Categories :

  • Graphs

Given an undirected graph with V vertices and E edges, create and return its adjacency list representation. Use 0-based indexing for the vertices.

An adjacency list is a data structure where for each vertex, we maintain a list of all other vertices it is connected to.

Constraints:

  • 1 ≤ V, E ≤ 105
  • Graph is undirected, meaning if there's an edge from u to v, there's also an edge from v to u
  • 0 ≤ u, v < V (vertices are 0-indexed)

Examples:

Input:
V = 5, E = 7
edges = [[0,1],[0,4],[4,1],[4,3],[1,3],[1,2],[3,2]]
Output: [[1,4],[0,2,3,4],[1,3],[1,2,4],[0,1,3]]
Explanation: For each vertex i, output[i] contains all vertices j where an edge exists between i and j.
Input:
V = 4, E = 3
edges = [[0,3],[0,2],[2,1]]
Output: [[2,3],[2],[0,1],[0]]
Explanation: The list for each vertex contains all vertices it has edges to.

Problem Solving

Input

What You'll Find Here

Interactive Exercises Practice coding with problems designed for beginners and experts.

Step-by-Step Solutions Understand every step of the solution process.

Real-World Scenarios Apply your skills to real-world problems and boost your confidence.

Choose from the following categories