Software Engineer (SDE)dsaintermediate3 interactive MCQs in app
Graph Representation: Adjacency List & Matrix
adjacency list O(V + E) vs matrix O(V^2)directed vs undirected edge insertionedge-lookup O(1) vs neighbor-scan O(deg)
Core Concept
Graphs connect vertices `V` via edges `E` (directed/undirected, weighted/unweighted). An **Adjacency List** (`adj[u] = [(v, w), ...]`) uses `O(V + E)` space and iterates neighbors of `u` cleanly in `O(deg(u))`, whereas an **Adjacency Matrix** (`M[u][v]`) uses `O(V^2)` space with `O(1)` edge-existence queries.
Worked Example
on a sparse graph with `V = 100,000` users and `E = 300,000` links, an Adjacency Matrix demands `10^10` cells (~40 GB!), crashing immediately, while an Adjacency List fits in a few MB!
Common Pitfall
forgetting to add BOTH `u -> v` and `v -> u` on undirected edges or forgetting disconnected components.
Recommended Readings & Practice
Practice Graph Representation: Adjacency List & Matrix with 3 graded MCQs & written feedback.
Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.