我正在斯坦福大学上一门在线算法课程,问题之一如下:
将路径的瓶颈定义为路径之一的最大长度 边缘。两个顶点s和t之间的最小瓶颈路径为 瓶颈不大于任何其他s-t路径的路径。 现在假设该图是无向的。给出线性时间(O(m)) 计算两个给定之间的最小瓶颈路径的算法 顶点。
使用改良的Dijkstra算法解决此问题,该算法在不满足要求的O(mlog(n))中运行。 Wikipedia声称存在
存在一种线性时间算法,用于在 无向图,即不使用最大生成树。的 该算法的主要思想是应用线性时间路径查找 算法来计算图中的边缘权重中位数,然后 根据删除所有较小的边缘或收缩所有较大的边缘 路径是否存在,并在结果中递归 较小的图。
有几个问题。该算法主要是挥舞着手,我不是在寻找最宽的路径,而是相反。
This的文章多于Wikipedia,但也没有涉及到过多的细节,尤其是在缩小边缘方面。
我已经写出了以下伪代码:
1: MBP(G, s, t)
2: if |E| == 1
3: return the only edge
4: else
5: x = median of all edge weights
6: E' = E - (v, w) where weight(v, w) < x
7: construct G'(V, E')
8: exists = is there a path from s to t in G'
9: if (exists == FALSE)
10: compute all the connected components Cᵢ of G'
11: reinsert the edges deleted into G'
12: G* = G'
13: for each Cᵢ
14: G* = SHRINK(G*, Cᵢ)
15: return MBP(G', s, t)
16: SHRINK(G, C)
17: leader = leader vertex of C
18: V* = {V(G) - C} ∪ {leader}
19: E* = {}
20: for each edge (v, w) ∈ E(G)
21: if v, w ∈ V*
22: E* = E* ∪ {(v, w, weight(v, w))}
23: else if v ∈ C, w ∈ V*
24: E* = E* ∪ {(leader, w, max(weight(v, w)))}
25: return G*(V*, E*)
我不明白的几件事:
答案 0 :(得分:0)
在这里OP。在my blog上可以找到详细的解决方案,但是伪代码如下:
1: CRITICAL-EDGE(G, s, t)
2: if |E(G)| == 1
3: return the only edge
4: else
5: x = median of all edge weights
6: X = E - (v, w) s.t. weight(v, w) > x
7: G' = G(V, X)
8: exists = is there a path from s to t in G'
9: if (exists == FALSE)
10: C = {C₁, C₂, ..., Cₖ} s.t. Cᵢ is a connected component of G
11: G' = G(V, E - X)
12: for i = 1 to |C|
13: G' = SHRINK(G', C, i)
14: else if X == E // no edges were deleted
15: X = {(v, w)} s.t. weight(v, w) = x
16: G' = G(V, X)
17: return CRITICAL-EDGE(G', s, t)
18: SHRINK(G, C, i)
19: leaderᵢ = leader vertex of C[i]
20: V* = {V(G) - C[i]} ∪ {leaderᵢ}
21: E* = {}
22: for each (v, w) ∈ E(G)
23: if v ∈ C[i], w ∈ C[j]
24: E* = E* ∪ {(leaderᵢ, leaderⱼ, min(weight(u, w)))} ∀ u ∈ C[i]
25: else if v, w ∉ C[i]
E * = E* ∪ {(v, w, weight(v, w))}
26: return G*(V*, E*)