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 from vertex i to vertex j.
Click to reveal answer
beginner
How do you represent no edge between two vertices in an adjacency matrix for an unweighted graph?
You represent no edge by placing 0 in the cell corresponding to those two vertices in the adjacency matrix.
Click to reveal answer
intermediate
In an adjacency matrix for a weighted graph, what value is typically used to represent no edge?
A special value like infinity (or a very large number) is used to represent no edge, depending on the implementation.
Click to reveal answer
beginner
What is the time complexity to check if an edge exists between two vertices using an adjacency matrix?
It is O(1) because you directly access the cell at row i and column j in the matrix.
Click to reveal answer
intermediate
What is a disadvantage of using adjacency matrix for graph representation?
It uses O(V²) space, which can be inefficient for large graphs with few edges (sparse graphs).
Click to reveal answer
What does a '1' in the cell (i, j) of an adjacency matrix represent in an unweighted graph?
AThe graph is weighted
BThere is no edge from vertex i to vertex j
CVertex i equals vertex j
DThere is an edge from vertex i to vertex j
✗ Incorrect
In an unweighted graph adjacency matrix, '1' means an edge exists from vertex i to vertex j.
What is the space complexity of an adjacency matrix for a graph with V vertices?
AO(V + E)
BO(V²)
CO(V)
DO(E²)
✗ Incorrect
An adjacency matrix uses a V by V 2D array, so space complexity is O(V²).
Which operation is fastest with an adjacency matrix?
AAdd a new vertex
BList all neighbors of a vertex
CCheck if an edge exists between two vertices
DRemove a vertex
✗ Incorrect
Checking edge existence is O(1) by direct matrix access.
In a weighted graph adjacency matrix, what does a cell value of 0 usually mean?
ANo edge exists
BEdge weight is one
CEdge weight is zero
DGraph is unweighted
✗ Incorrect
Typically, a special value like infinity or a very large number means no edge in weighted graphs; 0 can mean an edge with zero weight if allowed.
Which graph type is adjacency matrix less efficient for?
ASparse graphs
BDense graphs
CComplete graphs
DDirected graphs
✗ Incorrect
Adjacency matrix wastes space for sparse graphs with few edges.
Explain how an adjacency matrix represents edges in a graph and how to check if an edge exists between two vertices.
Think of a table where rows and columns are vertices.
You got /4 concepts.
Describe the advantages and disadvantages of using an adjacency matrix for graph representation.
Consider speed versus memory use.
You got /4 concepts.
Practice
(1/5)
1. What does an adjacency matrix represent in graph theory?
easy
A. A queue of nodes to visit
B. A list of nodes in the graph
C. A 2D array showing edges between nodes
D. A stack of visited nodes
Solution
Step 1: Understand adjacency matrix concept
An adjacency matrix is a 2D array where rows and columns represent nodes.
Step 2: Identify what the matrix stores
Each cell shows if an edge exists between two nodes (1 for edge, 0 for no edge).
Final Answer:
A 2D array showing edges between nodes -> Option C
Quick Check:
Adjacency matrix = 2D array of edges [OK]
Hint: Adjacency matrix is always a 2D array showing connections [OK]
Common Mistakes:
Confusing adjacency matrix with adjacency list
Thinking it stores node values instead of edges
Mixing up matrix with traversal order
2. Which of the following is the correct way to declare an adjacency matrix for 4 nodes in C#?
easy
A. int[] matrix = new int[4];
B. int[,] matrix = new int[4,4];
C. int[][] matrix = new int[4];
D. int matrix = new int[4,4];
Solution
Step 1: Identify correct 2D array syntax in C#
In C#, a 2D array is declared as int[,] with size [rows, columns].
Step 2: Check each option
int[,] matrix = new int[4,4]; uses int[,] with size [4,4], correct for adjacency matrix of 4 nodes.
Final Answer:
int[,] matrix = new int[4,4]; -> Option B
Quick Check:
2D array syntax = int[,] [OK]
Hint: Use int[,] for 2D arrays in C# [OK]
Common Mistakes:
Using jagged array syntax instead of 2D array
Declaring 1D array for adjacency matrix
Missing comma in array declaration
3. Given the following adjacency matrix for a graph with 3 nodes: