Lab06 Graphs
Lab06 Graphs
Lab 6 Graphs
Learning Outcome
Understand how to represent a graph using adjacency matrix and adjacency list.
Understand how Depth-First Search works.
Understand how Breadth-First Search works.
Understand how Topological Sorting works.
1. (10 min) The following undirected graph is provided. Undirected graph is considered bi-directional.
Write down its adjacency matrix representation and adjacency list representation.
A
5
9
3
B 7 D E
1 4
8
C
2. Performing DFS on a connected graph produces a spanning tree. Use the graph in question 1 to
answer the following questions.
(a) (20 min) There are 4 possible spanning trees when starting DFS from A. Draw all of them.
1
(b) (20 min) There are 6 possible spanning trees when starting DFS from B. Draw all of them.
3. Performing BFS on a connected graph also produces a spanning tree. Use the graph in question 1 to
answer the following questions.
(a) (10 min) There is only one possible spanning tree if we start BFS from A. Draw it.
(b) (20 min) There are 2 possible spanning trees when starting BFS from B. Draw all of them.
2
4. (10 min) The following directed acyclic graph (DAG) is provided.
(a) Write down its adjacency matrix representation and adjacency list representation.
A
5
9
3
B 7 D E
1 4
8
C
(b) Is the answer you obtained here the same as the one from Question 1?
5. (20 min) Topological Sorting for a graph allows us to find the sequence that satisfies the precedence
constraints. Find the Topological Sorting for the graph in Question 4. There are 2 possible answers.
6. What is the time complexity for DFS, BFS, and Topological Sorting? What is the data structure that
must be used in order to achieve the time complexity you mentioned?