数据结构图题库

1、有向图G如下图所示,请写出所有拓扑排序序列。所有的顶点都直接用其数字标号表示,如拓扑排序序列为25.png,那么请写成1234(中间没有空格)。不同的拓扑排序序列按照字典序排序,中间用一个空格隔开。

Screen Shot 2016-10-20 at 21.36.40.png

解析

根据拓扑排序的定义,顶点1必须在顶点3前,顶点1、顶点2和顶点3必须在顶点4前,故排列可以为1234、1324、2134

答案: 1234 1324 2134

2、无向图G=(V, E),其中:V={a, b, c, d, e, f}, E={(a, b), (a, e), (a, c), (b, e), (c, f), (f, d), (e, d)},对该图进行深度优先遍历(优先访问编号小的结点),得到的顶点序列为?

 A、abedfc

 B、aebdfc

 C、abcedf

解析

根据深度优先的算法,先访问a,再访问a的邻接顶点b,再访问b的邻接顶点e,访问e的邻接顶点d,访问d的邻接顶点f(注意是无向图),访问f的邻接顶点c,不再有没访问的顶点,结束,答案abedfc 

3、下列关于最短路算法的说法正确的有:

 A、当图中不存在负权回路但是存在负权边时,Dijkstra算法不一定能求出源点到所有点的最短路。 When the graph doesn't contain circuit of negative weight, but contains the edge of negative weight. Dijkstra algorithm can't guarantee the correctness of the algorithm.

 B、当图中不存在负权边时,Dijkstra算法能求出每对顶点间最短路径。 When the graph doesn't contain edge of negative weight, Dijkstra algorithm can calculate the shortest path of each pair of vertices.

 C、当图中存在负权回路时,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.

 D、Dijkstra算法不能用于每对顶点间最短路计算。Dijkstra algorithm can't be applied to calculate the shortest path of each pair of vertices.

解析

A.即使是只有负权边,也会导致以前已经被选出来更新其它结点最短路值的结点的最短路值被更新,造成错误。

B.可以执行多次Dijkstra算法实现这一要求。

C.Dijkstra算法无法处理图中存在任何负权边的情况。

D.可以执行多次Dijkstra算法实现这一要求。

4、请使用Kruskal算法求出下图的最小生成树,依次写出每次被选择的合法的合并代价最小的边的编号(如果同时存在多条边满足要求,选择编号最小的)。顶点a到顶点b (a < b)之间的边编号为ab,例如图中权值为1的边编号为02。

Screen Shot 2016-10-20 at 21.47.02.png

解析

Kruskal算法优先选择权值小的边,先挑选权值为1的边02,再选择权值为2的边35,再选择权值为3的边14,再选择权值为4的边25,再选择权值为5的边,只有选择12才能连接两个不同的连通分支,故答案为02 35 14 25 12

答案: 02 35 14 25 12

5、题图为一无向图,分别写出从顶点1出发,按深度优先搜索遍历算法得到的顶点序列,和按广度优先搜索遍历算法得到的顶点序列

Screen Shot 2016-10-20 at 21.48.52.png

解析

根据深度优先定义,先访问1,依次是2、3、4、5、6,注意是无向图。广度优先是一层一层访问,即123564,答案为123456 123564 

答案: 123456 123564

猜你喜欢

转载自blog.csdn.net/wydyd110/article/details/81333722