我正在通过“计算机算法基础”一书寻找多阶段图问题。
它说:
Algorithm Graph(G,k,n,p)
{
cost[n]=0;
for j=n-1 to 1 step -1 do
{
Let r be a vertex such that<j,r> is an edge of G and c[j,r]+cost[r] is minimum
cost[j]=c[j,r]+cost[r]
}
}
作者说复杂度是 O(|V| + |E|)。|V| 是顶点数,|E| 是边数。
我知道 for 循环针对顶点总数运行,并且内线必须选择一个近边。
我无法理解背后的逻辑