0
0
DSA Typescriptprogramming~5 mins

Adjacency List vs Matrix When to Choose Which in DSA Typescript - Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is an adjacency list in graph representation?
An adjacency list stores each node and a list of its neighbors. It uses less space for sparse graphs and is efficient for iterating over neighbors.
Click to reveal answer
beginner
What is an adjacency matrix in graph representation?
An adjacency matrix is a 2D array where each cell shows if there is an edge between two nodes. It uses more space but allows quick edge checks.
Click to reveal answer
intermediate
When is it better to use an adjacency list over an adjacency matrix?
Use adjacency list when the graph is sparse (few edges) because it saves space and is faster to traverse neighbors.
Click to reveal answer
intermediate
When is an adjacency matrix preferred over an adjacency list?
Use adjacency matrix when the graph is dense (many edges) or when you need to quickly check if an edge exists between two nodes.
Click to reveal answer
intermediate
What is the space complexity difference between adjacency list and adjacency matrix?
Adjacency list uses O(V + E) space, where V is vertices and E is edges. Adjacency matrix uses O(V²) space regardless of edges.
Click to reveal answer
Which graph representation is more space efficient for a graph with 1000 nodes and 10 edges?
ANone of the above
BAdjacency Matrix
CBoth use the same space
DAdjacency List
Which representation allows O(1) time to check if an edge exists between two nodes?
ABoth
BAdjacency List
CAdjacency Matrix
DNeither
For a dense graph, which representation is generally better?
AAdjacency List
BAdjacency Matrix
CDepends on the programming language
DDepends on the number of nodes only
What is the space complexity of an adjacency matrix for a graph with V vertices?
AO(V²)
BO(V + E)
CO(E)
DO(log V)
Which representation is faster to iterate over all neighbors of a node?
AAdjacency List
BAdjacency Matrix
CBoth are equally fast
DDepends on the number of nodes
Explain when you would choose an adjacency list over an adjacency matrix for graph representation.
Think about graphs with few edges compared to nodes.
You got /3 concepts.
    Describe the advantages and disadvantages of using an adjacency matrix.
    Consider time and space trade-offs.
    You got /3 concepts.