1、第八章 图PROBLEM 1 (1/1 分)下图中的强连通分量的个数为多少个?How many strongly connected graphs in the under graph?33 - 正确 33Explanation有向图强连通的极大子图称为该有向图的强连通分支或者强连通分量。分别为最左边 1 个点组成的极大子图,中间 4 个点组成的极大子图和最右边 1 个点组成的极大子图。分别为最左边 1 个点,中间 4 个点和最右边 1 个点。Maximal strongly connected subgraphs of a directed graph are called strongly
2、 connected components of this directed graph.They are the subgraph consist of the left-most vertex, the subgraph consist of 4 vertices in the middle, ,and the subgraph consist of the right-most vertex respectively.PROBLEM 2 (1/1 分)下面关于图的说法正确的有 (多选)The right statements of graphs in the following are:
3、 (There are more than one correct answers)对于无向图,所有结点的度数加起来一定是偶数。 As for undirected graphs, the sum of degrees of all vertices is definitely even number., 将有向图的一个强连通分量中的边全部反向仍然是强连通分量。Reversion all the edges of a strongly connected component of a directed graph, then the subgraph is still a strongly c
4、onnected component., - 正确 对于无向图,所有结点的度数加起来一定是偶数。 As for undirected graphs, the sum of degrees of all vertices is definitely even number. 将有向图的一个强连通分量中的边全部反向仍然是强连通分量。Reversion all the edges of a strongly connected component of a directed graph, then the subgraph is still a strongly connected componen
5、t. 对于有向图,每个结点的出度必须要等于入度。 As for directed graph, each vertices out-degree is equal to its in-degree. 对于一个连通图,一定存在一种给边添加方向的方案使得这个图变成强连通图。For a connected graph, there must be a way of directing all the edges of the original graph to make the graph strongly connected graph. Explanation结点度数是边数的 2 倍,故一定为偶
6、数。The sum of degrees of vertices is equal to the amount of edge times 2, so it must be even number.原来强连通分量中的点必须能够互达,边全部反向后,仍然能够互达。而原来强连通分量外的点和强连通分量内的点之间的边没有变化,以前不能互达现在还是不能,这样保证了仍然是极大的强连通子图。In the original strongly connected component, every pair of vertices in the subgraph is connected by a path.Aft
7、er reversion, this property doesnt change. And the connectivity of the vertices outside of the subgraph and vertices in the subgraph dont change too. So we can guarantee it still be the maximal strongly connected subgraph.所有结点的出度之和等于入度之和,但是每个结点并没有出度和入度相等的性质。The sum of in-degrees of all nodes is equa
8、l to the sum of out-degrees of all nodes. But for each node, it doesnt work.给两个结点新增一条边相连,能够形成一个连通图,但是不管怎么给边定向都不能使其成为强连通图。Add an edge of two vertex, then we can get a connected graph. But we cant make it strongly connected graph however we direct the edges.PROBLEM 3 (1/1 分)当各边上的权值满足什么要求时,宽度优先搜索算法可用来解
9、决单源最短路径问题? (单选)What requirement do the weight of edges should satisfied to make width-first search algorithm can solve single source shortest path problem? (There is only one correct answer)不一定相等 No limitation. 均互不相等 Each edge is not equal to each other. 均相等 Equal 均相等 Equal - 正确 Explanation均相等 宽度优先搜
10、索算法的搜索状态树是一层一层的扩展结点的,而当边权均相等时,步数越少距离越短,所以可以直接用宽度优先搜索算法解决。Equal Width-first search algorithms search-state-tree expands layer by layer. When the weight of edges is equal to each other, lesser step corresponds to shorter distance, so we can use width-first search algorithm to solve problem.均互不相等 宽度优先搜
11、索算法的搜索状态树是一层一层的扩展结点的,而当边权均相等时,步数越少距离越短,所以可以直接用宽度优先搜索算法解决。Each edge is not equal to each other. Width-first search algorithms search-state-tree expands vertices layer by layer. When the weight of edges is equal to each other, lesser step corresponds to shorter distance, so we can use width-first sear
12、ch algorithm to solve problem.不一定相等 宽度优先搜索算法的搜索状态树是一层一层的扩展结点的,而当边权均相等时,步数越少距离越短,所以可以直接用宽度优先搜索算法解决。No limitation. Width-first search algorithms search-state-tree expands vertices layer by layer. When the weight of edges is equal to each other, lesser step corresponds to shorter distance, so we can us
13、e width-first search algorithm to solve problem.PROBLEM 4 (1/1 分)下列关于最短路算法的说法正确的有:(多选)The right statements of the following are: (There are more than one correct answers)当图中不存在负权回路但是存在负权边时,Dijkstra 算法不一定能求出源点到所有点的最短路。 When the graph doesnt contain circuit of negative weight, but contains the edge of
14、 negative weight. Dijkstra algorithm cant guarantee the correctness of the algorithm., 当图中不存在负权边时,Dijkstra 算法能求出每对顶点间最短路径。 When the graph doesnt contain edge of negative weight, Dijkstra algorithm can calculate the shortest path of each pair of vertices., - 正确 当图中不存在负权回路但是存在负权边时,Dijkstra 算法不一定能求出源点到
15、所有点的最短路。 When the graph doesnt contain circuit of negative weight, but contains the edge of negative weight. Dijkstra algorithm cant guarantee the correctness of the algorithm. 当图中不存在负权边时,Dijkstra 算法能求出每对顶点间最短路径。 When the graph doesnt contain edge of negative weight, Dijkstra algorithm can calculate
16、 the shortest path of each pair of vertices. 当图中存在负权回路时,Dijkstra 算法也一定能求出源点到所有点的最短路。 When the graph contains the circuit of negative weight, Dijkstra algorithm can certainly calculate the shortest path form the single source to all the vertices. Dijkstra 算法不能用于每对顶点间最短路计算。 Dijkstra algorithm cant be
17、applied to calculate the shortest path of each pair of vertices. Explanation当图中不存在负权回路但是存在负权边时,Dijkstra 算法不一定能求出源点到所有点的最短路。 即使是只有负权边,也会导致以前已经被选出来更新其它结点最短路值的结点的最短路值被更新,造成错误。当图中不存在负权边时,Dijkstra 算法能求出每对顶点间最短路径。 可以执行多次 Dijkstra 算法实现这一要求。当图中存在负权回路时,Dijkstra 算法也一定能求出源点到所有点的最短路。 Dijkstra 算法无法处理图中存在任何负权边的情况
18、。Dijkstra 算法不能用于每对顶点间最短路计算。 可以执行多次 Dijkstra 算法实现这一要求。When the graph doesnt contain circuit of negative weight, but contains the edge of negative weight. Dijkstra algorithm cant guarantee the correctness of the algorithm.Even if there is only the edge of negative weight, it would result in that the s
19、hortest path of the node which be selected previously to update the shortest path of the other vertices changes, then cause errors.When the graph doesnt contain edge of negative weight, Dijkstra algorithm can calculate the shortest path of each pair of vertices. We can perform Dijkstra algorithm rep
20、eatedly to satisfy this requirement.When the graph contains the circuit of negative weight, Dijkstra algorithm can certainly calculate the shortest path form the single source to all the vertices.Dijkstra algorithm cant handle the situation that graph contains any edge of negative weight.Dijkstra al
21、gorithm cant be applied to calculate the shortest path of each pair of vertices. We can perform Dijkstra algorithm repeatedly to satisfy this requirement.PROBLEM 5 (1/1 分)请使用 Kruskal 算法求出下图的最小生成树,依次写出每次被选择的合法的合并代价最小的边的编号(如果同时存在多条边满足要求,选择编号最小的)。顶点 a 到顶点 b (a b)之间的边编号为 ab,例如图中权值为 1 的边编号为02。(不同编号之间用一个空
22、格分隔)Please use Kruskal algorithm to the following graph and find the minimum spanning tree, and write the number of the valid vertex with minimum merging cost in turn(if there are many vertices satisfy requirement, choose the vertex with minimum number ). The number of the edge connecting vertex a a
23、nd vertex b is ab. Like the edge with weight 1 in the graph, its number is 02(different numbers separated by a blank space).02 35 14 25 02 35 14 25 12 - 正确 02 35 14 25 12ExplanationKruskal 算法优先选择权值小的边,先挑选权值为 1 的边 02,再选择权值为 2的边 35,再选择权值为 3 的边 14,再选择权值为 4 的边 25,再选择权值为 5的边,只有选择 12 才能连接两个不同的连通分支,故答案为 02
24、 35 14 25 12Edges with small weight are given high priority to be chose in the Kruskal algorithm. We firstly choose the edge 02 with weight 1, then choose edge 35 with weight 2, then choose edge 14 with weight 3, then choose the edge 25 with weight 4, then choose the edge with weight 5, and only the
25、 edge 12 can connect two different connected components. So the answer is 02 34 14 25 12.PROBLEM 6 (1/1 分)请使用 Prim 算法从结点 0 出发求下图的最小生成树,依次写出每次被加入到最小生成树中边的编号(如果同时存在多条边满足要求,选择编号最小的)。顶点 a 到顶点 b (a b)之间的边编号为 ab,例如图中权值为 1 的边编号为 02。(不同编号之间用一个空格分隔)Please use prim algorithm starting from vertex 0 to find the
26、 minimum spanning tree of the following graph, write the number of the edge added into the minimum spanning tree in turn(if there are many vertices satisfy requirement, choose the vertex with minimum number). The number of the edge connecting vertex a and vertex b is ab. Like the edge with weight 1
27、in the graph, its number is 02(different numbers separated by a blank space).02 25 35 12 02 25 35 12 14 - 正确 02 25 35 12 14Explanation最小生成树中已经选择的顶点的集合 U 初始为0 ,从 0 起,先挑选其他节点到 0 权值最小为 1 的边 02,把顶点 2 加入 U,U 变为0,2,再选择到 U权值最小为 4 的边 25,U 变为0,2,5,再选择到 U 权值最小为 2 的边35,U 变为0,2,5,3,再选择到 U 权值最小为 5 的边 12,U 变为0,2,
28、5,3,1,再选择到 U 权值最小为 3 的边 14,U 变为0,2,5,3,1,4,结束,答案为 02 25 35 12 14The original set of the selected vertices of the minimum spanning tree is 0. We firstly select the edge with the minimum weight of edges which connect vertex 0 and other vertices. So we select edge 02 with weight 1 and add vertex 2 into
29、 U, then U becomes 0, 2. Next, in the set of edges which connect U and others, we select the edge 25 with the minimum weight 4, then U becomes 0, 2, 5. Next, in the set of edges which connect U and others, we select the edge 35 with the minimum weight 2, then U becomes 0, 2, 5, 3.Similarly, then we
30、select the edge 12 with the minimum weight 12, U becomes 0, 2, 5, 3, 1. Then we select the edge 14 with the minimum weight 3, then U becomes 0, 2, 5, 3, 1, 4, over. The answer is 02 25 35 12 14PROBLEM 7 (本题共有 1 分)题图为一无向图,分别写出从顶点 1 出发,按深度优先搜索遍历算法得到的顶点序列,和按广度优先搜索遍历算法得到的顶点序列注意:1.优先访问编号小的结点2.顶点序列内无空格,先写
31、深度优先搜索遍历序列,再写广度优先搜索遍历序列。3.深度优先搜索遍历序列和广度优先搜索遍历序列之间用空格隔开The following graph is an undirected graph, please write the vertices sequences obtained by the depth-first search traversal algorithm and width-first search traversal algorithm respectively.Notice:1. The vertex with smaller number should have hi
32、gher priority to be visited.2. There is no blank space among the vertices sequences, write the sequence produced by the depth-first search traversal algorithm at first, then write the another one.3. There two sequences should be separated by a blank space.123456 123564Explanation根据深度优先定义,先访问 1,依次是 2
33、、3、4、5、6,注意是无向图。广度优先是一层一层访问,即 123564,答案为 123456 123564According to the definition of the depth-first, we firstly visit vertex 1, then 2, 3, 4, 5, 6 in turn, you should noticed that its undirected graph. Width-first traversal algorithm visit the vertices layer by layer,the sequence is 123564. So the answer is 123456 123564.