Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is an adjacency matrix in graph representation?
An adjacency matrix is a 2D array where each cell at row i and column j indicates if there is an edge between vertex i and vertex j. It uses rows and columns to represent connections.
Click to reveal answer
beginner
What is an adjacency list in graph representation?
An adjacency list represents a graph by storing a list of neighbors for each vertex. Each vertex has a list of vertices it connects to, making it efficient for sparse graphs.
Click to reveal answer
intermediate
Which graph representation uses more memory for large sparse graphs: adjacency matrix or adjacency list?
Adjacency matrix uses more memory for large sparse graphs because it stores information for every possible edge, even if many edges don't exist. Adjacency list only stores existing edges.
Click to reveal answer
intermediate
How does checking if an edge exists differ between adjacency matrix and adjacency list?
In an adjacency matrix, checking if an edge exists is fast and direct by looking up the cell. In an adjacency list, you may need to search through the list of neighbors, which can be slower.
Click to reveal answer
beginner
When is it better to use an adjacency list over an adjacency matrix?
Use an adjacency list when the graph has few edges compared to the number of vertices (sparse graph). It saves memory and is efficient for iterating over neighbors.
Click to reveal answer
Which graph representation uses a 2D array to store edges?
AAdjacency matrix
BAdjacency list
CEdge list
DIncidence matrix
✗ Incorrect
An adjacency matrix uses a 2D array where rows and columns represent vertices and cells indicate edges.
Which representation is more memory efficient for a graph with very few edges?
AAdjacency matrix
BAdjacency list
CBoth use the same memory
DNone of the above
✗ Incorrect
Adjacency lists store only existing edges, so they use less memory for sparse graphs.
How do you check if an edge exists between two vertices in an adjacency matrix?
ALook up the cell at row i and column j
BSearch the list of neighbors for vertex i
CCount the total edges
DCheck the degree of vertex j
✗ Incorrect
In an adjacency matrix, the presence of an edge is directly indicated by the value in the cell at row i and column j.
Which graph representation is better for quickly iterating over all neighbors of a vertex?
AAdjacency matrix
BEdge list
CAdjacency list
DNone of the above
✗ Incorrect
Adjacency lists store neighbors directly, making iteration over them faster and more efficient.
What is a disadvantage of using an adjacency matrix?
ADoes not support weighted edges
BCannot represent directed graphs
CEdges are hard to find
DUses a lot of memory for large graphs
✗ Incorrect
Adjacency matrices use memory for every possible edge, which can be large for big graphs, especially if many edges are missing.
Explain the difference between adjacency matrix and adjacency list in graph representation.
Think about how each stores connections and when each is useful.
You got /4 concepts.
When would you choose an adjacency list over an adjacency matrix? Give reasons.
Consider the number of edges compared to vertices.
You got /4 concepts.
Practice
(1/5)
1. Which graph representation uses a 2D grid to show connections between nodes?
easy
A. Incidence matrix
B. Adjacency matrix
C. Edge list
D. Adjacency list
Solution
Step 1: Understand adjacency matrix structure
An adjacency matrix is a 2D grid where rows and columns represent nodes, and cells show if an edge exists.
Step 2: Compare with other representations
Adjacency lists store neighbors in lists, not grids. Edge lists and incidence matrices differ in format.
Final Answer:
Adjacency matrix -> Option B
Quick Check:
2D grid = adjacency matrix [OK]
Hint: Matrix means grid; list means neighbors [OK]
Common Mistakes:
Confusing adjacency list with matrix
Thinking edge list is a grid
Mixing incidence matrix with adjacency matrix
2. Which of the following is the correct way to represent an adjacency list in Python?
easy
A. graph = [[1, 2], 0, [0, 1]]
B. graph = [[0,1,0],[1,0,1],[0,1,0]]
C. graph = [(0,1), (1,2), (2,0)]
D. graph = {0: [1, 2], 1: [0], 2: [0, 1]}
Solution
Step 1: Identify adjacency list format
An adjacency list maps each node to a list of its neighbors, often using a dictionary in Python.
Step 2: Check each option
graph = {0: [1, 2], 1: [0], 2: [0, 1]} uses a dictionary with keys as nodes and values as neighbor lists, which is correct. graph = [[0,1,0],[1,0,1],[0,1,0]] is a matrix, C is an edge list, D incorrectly uses an integer 0 for node 1 instead of a list.