What is an adjacency matrix in graph representation?
An adjacency matrix is a 2D array used to represent a graph, where each cell at row i and column j indicates if there is an edge between vertex i and vertex j.
Click to reveal answer
beginner
How do you represent no edge between two vertices in an adjacency matrix?
You represent no edge by placing 0 (zero) in the matrix cell corresponding to those vertices.
Click to reveal answer
beginner
What is the size of an adjacency matrix for a graph with n vertices?
The adjacency matrix size is n x n, where n is the number of vertices in the graph.
Click to reveal answer
intermediate
How does an adjacency matrix represent an undirected graph?
In an undirected graph, the adjacency matrix is symmetric, meaning the value at [i][j] is the same as at [j][i].
Click to reveal answer
intermediate
What is a disadvantage of using adjacency matrices for sparse graphs?
Adjacency matrices use a lot of memory for sparse graphs because they store all possible edges, even if many do not exist.
Click to reveal answer
What value is stored in an adjacency matrix cell if there is an edge between vertex 2 and vertex 3?
A1
B0
C-1
Dnull
✗ Incorrect
A value of 1 indicates an edge exists between the two vertices.
What is the time complexity to check if an edge exists between two vertices in an adjacency matrix?
AO(n)
BO(n^2)
CO(1)
DO(log n)
✗ Incorrect
Checking an edge is direct access in the matrix, so it takes constant time O(1).
Which graph type usually wastes memory when using adjacency matrices?
ASparse graph
BComplete graph
CDirected graph
DWeighted graph
✗ Incorrect
Sparse graphs have few edges, so adjacency matrices waste memory storing many zeros.
In an undirected graph's adjacency matrix, what is true about the matrix?
AIt is lower triangular
BIt is symmetric
CIt is upper triangular
DIt is diagonal
✗ Incorrect
The matrix is symmetric because edges go both ways between vertices.
What does a 0 in the adjacency matrix cell [i][j] mean?
AGraph is weighted
BEdge exists between vertex i and j
CVertex i equals vertex j
DNo edge between vertex i and j
✗ Incorrect
Zero means no edge exists between those vertices.
Explain how an adjacency matrix represents edges in a graph and how to interpret its values.
Think of a table where rows and columns are points connected by lines.
You got /5 concepts.
Describe the advantages and disadvantages of using adjacency matrices for graph representation.
Consider speed versus memory use.
You got /4 concepts.
Practice
(1/5)
1. What does an adjacency matrix represent in a graph?
easy
A. A 2D array showing connections between nodes
B. A list of nodes in the graph
C. A sequence of edges in order
D. A tree structure of nodes
Solution
Step 1: Understand adjacency matrix structure
An adjacency matrix is a 2D array where rows and columns represent nodes.
Step 2: Identify what the matrix stores
Each cell shows if there is a connection (edge) between two nodes.
Final Answer:
A 2D array showing connections between nodes -> Option A
Quick Check:
Adjacency matrix = 2D array of connections [OK]
Hint: Adjacency matrix is always a 2D array of node links [OK]
Common Mistakes:
Confusing adjacency matrix with adjacency list
Thinking it stores node values instead of connections
Assuming it is a sequence or tree
2. Which of the following is the correct way to declare a 3x3 adjacency matrix in JavaScript?
easy
A. const matrix = [0,0,0];
B. const matrix = [[0,0,0],[0,0,0],[0,0,0]];
C. const matrix = new Array(3);
D. const matrix = {0:0,1:0,2:0};
Solution
Step 1: Understand adjacency matrix as 2D array
It must be an array of arrays, each inner array representing a row.
Step 2: Check each option's structure
const matrix = [[0,0,0],[0,0,0],[0,0,0]]; is a 3x3 array filled with zeros, correct for adjacency matrix initialization.
Final Answer:
const matrix = [[0,0,0],[0,0,0],[0,0,0]]; -> Option B