What is an adjacency list in graph representation?
An adjacency list stores each node with a list of its connected neighbors. It uses less space for sparse graphs and is efficient for traversing neighbors.
Click to reveal answer
beginner
What is an adjacency matrix in graph representation?
An adjacency matrix is a 2D array where each cell [i][j] shows if there is an edge between node i and node j. 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 an adjacency list when the graph is sparse (few edges) because it saves memory and is faster to iterate neighbors.
Click to reveal answer
intermediate
When is an adjacency matrix preferred?
Use an 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 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 memory efficient for a graph with 1000 nodes and 10 edges?
AAdjacency List
BAdjacency Matrix
CBoth use the same memory
DNone of the above
✗ Incorrect
Adjacency list uses less memory for sparse graphs like this one with few edges.
Which representation allows O(1) time to check if an edge exists between two nodes?
AAdjacency List
BNeither
CBoth
DAdjacency Matrix
✗ Incorrect
Adjacency matrix stores edges in a 2D array, so checking an edge is a direct lookup.
For a dense graph, which representation is usually better?
AAdjacency List
BAdjacency Matrix
CLinked List
DStack
✗ Incorrect
Dense graphs have many edges, so adjacency matrix is efficient for storage and edge checks.
What is the main disadvantage of adjacency matrix for large sparse graphs?
AComplex to implement
BSlow edge lookup
CHigh memory usage
DCannot represent directed edges
✗ Incorrect
Adjacency matrix uses O(V²) space, which is large for sparse graphs.
Which representation is better for iterating over all neighbors of a node?
AAdjacency List
BAdjacency Matrix
CBoth are equal
DNone
✗ Incorrect
Adjacency list stores neighbors directly, making iteration faster and simpler.
Explain when to choose adjacency list versus adjacency matrix for graph representation.
Think about number of edges and how fast you want to check connections.
You got /4 concepts.
Describe the space complexity of adjacency list and adjacency matrix and why it matters.
Consider how many nodes and edges the graph has.
You got /4 concepts.
Practice
(1/5)
1. Which data structure is generally better for representing a graph with many nodes but very few edges?
easy
A. Adjacency List
B. Adjacency Matrix
C. Array
D. Stack
Solution
Step 1: Understand graph density
A graph with many nodes but few edges is called a sparse graph.
Step 2: Choose data structure for sparse graph
Adjacency List stores only existing edges, saving space for sparse graphs.
Final Answer:
Adjacency List -> Option A
Quick Check:
Sparse graph = Adjacency List [OK]
Hint: Sparse graph? Use adjacency list for space efficiency [OK]
Common Mistakes:
Choosing adjacency matrix for sparse graphs wastes space
Confusing sparse with dense graphs
Thinking arrays or stacks represent graphs directly
2. Which of the following is the correct way to declare an adjacency matrix for a graph with 4 nodes in C#?
easy
A. int[][] adjacencyMatrix = new int[4][]; for(int i=0; i<4; i++) adjacencyMatrix[i] = new int[4];
B. int adjacencyMatrix = new int[4];
C. List<int>[] adjacencyMatrix = new List<int>[4];
D. int[,] adjacencyMatrix = new int[4,4];
Solution
Step 1: Identify adjacency matrix type
An adjacency matrix is a 2D array representing edges between nodes.
Step 2: Check C# syntax for 2D arrays
In C#, 2D arrays use syntax like int[,] array = new int[rows, columns];
Final Answer:
int[,] adjacencyMatrix = new int[4,4]; -> Option D
Only matrix[0,1], matrix[1,2], and matrix[2,0] are set to 1; matrix[1,0] remains 0.
Step 2: Understand default values in int[] arrays
Unassigned int elements default to 0 in C#.
Final Answer:
0 because matrix[1,0] was never set -> Option B
Quick Check:
Unset matrix elements = 0 [OK]
Hint: Unset matrix cells default to 0, not symmetric [OK]
Common Mistakes:
Assuming adjacency matrix is symmetric by default
Expecting runtime error for valid indices
Confusing default values with assigned values
5. You need to represent a social network graph with 10,000 users where each user has on average 10 friends. Which representation is best and why?
Choose between adjacency list and adjacency matrix.
hard
A. Adjacency list, because it uses less memory for sparse graphs
B. Adjacency matrix, because it allows quick edge checks
C. Adjacency matrix, because it is simpler to implement
D. Adjacency list, because it stores all possible edges
Solution
Step 1: Calculate graph density
10,000 users with 10 friends each means about 100,000 edges, which is sparse compared to 100 million possible edges.
Step 2: Choose data structure for sparse graph
Adjacency list stores only existing edges, saving huge memory compared to adjacency matrix.
Final Answer:
Adjacency list, because it uses less memory for sparse graphs -> Option A
Quick Check:
Sparse large graph = adjacency list [OK]
Hint: Large sparse graph? Use adjacency list for memory efficiency [OK]