CBMS-2024A-09
题目来源:Question 9
日期:2024-07-31
题目主题:CS-算法-图算法
Solution
(1) Write the adjacency list for the given graph
graph TB;
1 --- 3
1 --- 2
3 --- 2
3 --- 5
2 --- 5
2 --- 4
5 --- 4
5 --- 6
4 --- 6
The adjacency list for the given graph is:
1:2:3:4:5:6: 2,3 1,3,4,5 1,2,5 2,5,6 3,4,2,6 5,4
(2) Draw the graph for the given adjacency list
1:2:3:4:5:6:7: 2,3 1 1 5,6 4,6,7 4,5,7 5,6
graph LR;
1 --- 2;
1 --- 3;
4 --- 5;
4 --- 6;
5 --- 7;
6 --- 7;
(3) Depth-First Search (DFS) starting from node 2
A possible order to visit the nodes could be:
2→1→3→5→4
(4) Breadth-First Search (BFS) starting from node 2
A possible order to visit the nodes could be:
2→1→4→5→3
(5) Pseudocode for DFS to Find the Number of Connected Components with Explicit Use of Aij
(6) Pseudocode for BFS to Find the Number of Connected Components with Explicit Use of Aij
知识点
DFSBFS图算法图论
重点词汇
- Depth-First Search (DFS) 深度优先搜索
- Breadth-First Search (BFS) 广度优先搜索
- Adjacency List 邻接表
参考资料
- Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein, Chap. 22.
- Graph Theory with Applications, J.A. Bondy and U.S.R. Murty, Chap. 1.