1、北大PKU 慕课 EDX 数据结构与算法 第八章图 quiz与解析第八章 图Problem 1 (1/1 分)下图中的强连通分量的个数为多少个?How many strongly connected graphs in the under graph?3 - 正确 33Explanation有向图强连通的极大子图称为该有向图的强连通分支或者强连通分量。分别为最左边1个点组成的极大子图,中间4个点组成的极大子图和最右边1个点组成的极大子图。分别为最左边1个点,中间4个点和最右边1个点。Maximal strongly connected subgraphs of a directed graph
2、 are called strongly 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 i
3、n the following are: (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 subgra
4、ph is still a strongly connected 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 str
5、ongly connected component. 对于有向图,每个结点的出度必须要等于入度。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. 窗体底端Ex
6、planation结点度数是边数的2倍,故一定为偶数。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 i
7、s connected by a path.After 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-deg
8、rees of all nodes is equal 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 均相等 Eq
10、ual - 正确 窗体底端Explanation均相等 宽度优先搜索算法的搜索状态树是一层一层的扩展结点的,而当边权均相等时,步数越少距离越短,所以可以直接用宽度优先搜索算法解决。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 algor
11、ithm to solve problem.均互不相等 宽度优先搜索算法的搜索状态树是一层一层的扩展结点的,而当边权均相等时,步数越少距离越短,所以可以直接用宽度优先搜索算法解决。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 distanc
12、e, so we can use width-first search 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
13、to shorter distance, so we can use 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 negat
14、ive 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 the shortest path of each pair of vertices., - 正确 当图中不
15、存在负权回路但是存在负权边时,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. 当图中不存在负权边时,Dijkstra算法能求出每对顶点间最短路径。 When the graph doesnt contain edge of negative weight,
16、 Dijkstra algorithm can calculate 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算法不能用于每对顶点间最短路
17、计算。 Dijkstra algorithm cant be applied to calculate the shortest path of each pair of vertices. 窗体底端Explanation当图中不存在负权回路但是存在负权边时,Dijkstra算法不一定能求出源点到所有点的最短路。 即使是只有负权边,也会导致以前已经被选出来更新其它结点最短路值的结点的最短路值被更新,造成错误。当图中不存在负权边时,Dijkstra算法能求出每对顶点间最短路径。 可以执行多次Dijkstra算法实现这一要求。当图中存在负权回路时,Dijkstra算法也一定能求出源点到所有点的最短
18、路。 Dijkstra算法无法处理图中存在任何负权边的情况。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
19、would result in that the shortest 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 perf
20、orm Dijkstra algorithm repeatedly 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 n
21、egative weight.Dijkstra algorithm 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的
22、边编号为02。(不同编号之间用一个空格分隔)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 con
23、necting vertex a and 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 12 - 正确 02 35 14 25 12ExplanationKruskal算法优先选择权值小的边,先挑选权值为1的边02,再选择权值为2的边35,再选择权值为3的边14,再选择权值为4的边25,再选择权值为5的边,只有选择12才能连接两个不同的连通分支,故答案为02 35 14 25
24、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 edge 12 c
25、an 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 minimum spanning tre
26、e 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 in the graph, its num
27、ber is 02(different numbers separated by a blank space).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,5,3,1,再选择到U权值最小为3的边14,U变为0,2,5,3,1,4,结束,答案为02 25 35 12 14The or
28、iginal 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 U, then U becomes 0, 2. Next, in the set of edges which connect U and
29、 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 select the edge 12 with the minimum weight 12, U becomes 0, 2, 5, 3, 1
30、. 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.顶点序列内无空格,先写深度优先搜索遍历序列,再写广度优先搜索遍历序列。3.深度优先搜索遍历序列和广度优先搜索遍历序列之间用空格隔开The following graph
31、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 higher priority to be visited.2. There is no blank space among the vertices
32、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、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 undir
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1