0% found this document useful (0 votes)
5 views3 pages

Lab06 Graphs

Uploaded by

Marwah Al-Helali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Lab06 Graphs

Uploaded by

Marwah Al-Helali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CCP6214 Algorithm Design and Analysis

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

Adjacency Matrix Adjacency List

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

Adjacency Matrix Adjacency List

(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?

You might also like