Week 8
Bottleneck minimum spanning tree.
题目
Given a connected edge-weighted graph, design an efficient algorithm to find a minimum bottleneck spanning tree. The bottleneck capacity of a spanning tree is the weights of its largest edge. A minimum bottleneck spanning tree is a spanning tree of minimum bottleneck capacity.
思路
根据这个定义……MST就是瓶颈生成树呀,因为其最大的权重边已经是所有生成结果里面最小的——这是MST的定义
设计
如上
Is an edge in a MST.
题目
Given an edge-weighted graph G and an edge e, design a linear-time algorithm to determine whether e appears in some MST of G.
Note: Since your algorithm must take linear time in the worst case, you cannot afford to compute the MST itself.
思路(非原创)
https://stackoverflow.com/questions/15049864/check-if-edge-is-included-in-some-mst-in-linear-time-non-distinct-values
MST环性质:如果图上存在一个环,其上一边的权重大于环上的其他边,那么这条边必不属于该图的MST
设计
对于指定的边,从其中一个端点DFS到另一端点,过程中只能走比指定边权重小的边
如果可达,那么指定边一定不在MST中
如果不可达,那么指定便一定在MST中(因为这种情况下,其不是两端点所在环上的权重最大边)
由于算法只涉及DFS,因此复杂度ο(E+V)\omicron(E+V)ο(E+V)
Minimum-weight feedback edge set.
题目
A feedback edge set of a graph is a subset of edges that contains at least one edge from every cycle in the graph. If the edges of a feedback edge set are removed, the resulting graph is acyclic. Given an edge-weighted graph, design an efficient algorithm to find a feedback edge set of minimum weight. Assume the edge weights are positive.
思路(非原创)
https://stackoverflow.com/questions/10791689/how-to-find-feedback-edge-set-in-undirected-graph
对于回边的取法,实际上是确定一个生成树,然后对图取补。因为生成树是绝对无环的,因此其补图便是我们想要的
设计
- 找到最小权重回边集,就可以使用两种MST算法找到图中各个通量的最大生成树,然后取补即可
- 拓展:对于无权图,使用DFS找到最大尺寸的生成树再取补就能找到最小回边集
Monotonic shortest path
问题
Given an edge-weighted digraph GGG, design an ElogEE \log EElogE algorithm to find a monotonic shortest path from sss to every other vertex. A path is monotonic if the sequence of edge weights along the path are either strictly increasing or strictly decreasing.
思路
要求设计一个算法,在ElogEE \log EElogE复杂度内找到一条权重单调(严格增加或严格减少)的最短路
设计
由于没确定有没有环,首选算法就是Dijkstra算法(ElogEE \log EElogE是最坏情况),对于寻找最短边的思路(出队)是不会变的,变就变在松弛的时候要确保权重单调。
Second shortest path
问题
Given an edge-weighted digraph and let PPP be a shortest path from vertex sss to vertex ttt. Design an ElogVE \log VElogV algorithm to find a path (not necessarily simple) other than PPP from sss to ttt that is as short as possible. Assume all of the edge weights are strictly positive.
思路
时间复杂度直接就是计算最短路
设计
使用一个对短路算法找到所有顶点的最短路。然后检查除当前t的前序节点外其他节点的松弛结果,取最小
Shortest path with one skippable edge
问题
Given an edge-weighted digraph, design an ElogVE \log VElogV algorithm to find a shortest path from sss to ttt where you can change the weight of any one edge to zero. Assume the edge weights are nonnegative.
思路(非原创)
https://stackoverflow.com/questions/16291676/shortest-path-with-one-skippable-edge
设计
首先,使用最短路找到s到所有顶点的最短路,在使用最短路找到所有顶点到v的最短路,然后考察每一条边v→wv \to wv→w,找到最小的S(v)+T(w)S(v)+T(w)S(v)+T(w),然后再将对应的边权重置0即可