Adjacency Matrix vs List | Data Structures Interview | Skill-Lync Resources
Easy Data Structures Graphs

What is the difference between adjacency matrix and adjacency list for graphs?

Answer

An adjacency matrix is a 2D array where matrix[i][j] indicates an edge between vertices i and j, using O(V^2) space with O(1) edge lookup but slow for sparse graphs. An adjacency list uses an array of lists where each vertex stores its neighbors, using O(V+E) space with O(degree) edge lookup, efficient for sparse graphs. Matrix suits dense graphs; list suits sparse graphs and most real-world scenarios.

Master These Concepts with IIT Certification
IIT Certified

Master These Concepts with IIT Certification

175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.

Relevant for Roles

Software Engineer Backend Developer Algorithm Developer