0
已知:未加權的有向圖(G =(E,V)),可以包含任意數量的循環。稀疏循環圖中最長的簡單路徑
目標:對所有的頂點我要V中的最長簡單路徑來一些目標頂點X
算法理念:
For each v in V
v.distanceToTarget = DepthFirstSearch(v)
Next
DepthFirstSearch(v as Vertex)
if v = target then
'Distance towards target is 0 for target itself
return 0
elseif v.isVisitedInCurrentDFSPath then
'Cycle found -> I wont find the target when I go around in cycles -> abort
return -infinity
else
'Return the maximum Distance of all Successors + 1
return max(v.Successors.ForEach(Function(v) DepthFirstSearch(v))) + 1
end if
這是正確的所有情況? (假設目標可以從每個頂點到達)
我的圖中的邊數很小。 假定| E | < = 3 * | V |成立。我如何計算平均時間複雜度?
謝謝!