English 中文(简体)
稍快一点的Bellman- Ford
原标题:A slightly faster Bellman-Ford

我对Bellman-Ford做了一点修改,所以它只起到“有用”的放松作用。这就是说,D(v)意味着的放松得到了更新。

define Relax(u, v):
 if d(v) > d(u) + w(u,v)         //w(u,v) = weight of edge u->v
    d(v) = d(u) + w(u,v)


INIT // our usual initialization.
Queue Q
Q ← s // Q holds vertices whose d(v) values have been updated recently.
While (Q not empty)
{
  u ← Frontof(Q);
  for each neighbor v of u
  {
    Relax(u, v)

    if d(v) was updated by Relax and v not in the Q  //Here s where we re a bit smarter
        ADD v to End of Q.                           //since we add to Q if 
                                                     //the relaxation changed d(v)
  }
}

现在, 如果所有最短路径都最多有 k 弧。 那么最坏的运行时间是 O( V*k), 因为我们只通过这个智能版本的 k 弧。 这比 { k} & lt; {\\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

有人能告诉我一个图表类型吗? 这个改良版没有比最初的Bellman-Ford算法更好吗?这就是说,最优的性能是O(V*E)

问题回答

考虑一下所有边缘都有负重量的图形。 在本图中, 顶点 u 如果有多个相容边缘, 将会多次添加到 Q 中 。

语句 k & lt; E is incolct: 如果在图形中出现负循环, k 是无限的





相关问题
Java: JGraphT: Iterate through nodes

I m trying to iterate through all nodes, so I can print them out for graphviz. What is the best way to do that using the JGraphT library? public static void main(String[] args) { UndirectedGraph&...

Java: Adding nodes to graph bug

Preface: I know that there are high quality graph APIs available. I m interested in writing my own for self-improvement. This is my function to add nodes: public void addNode(Vertex v, ...

Radial plotting algorithm

I have to write an algorithm in AS3.0 that plots the location of points radially. I d like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry ...

Microsoft .Net Chart Control not showing markers

I m using the Microsoft Chart Controls for Microsoft .NET Framework 3.5 and am having a spot of trouble getting Data Markers to show on the image. I m generating the chart at run-time, so can t just ...

3D graphs using pChart

Is there a way to draw a 3D Bar Graph using the pChart library in PHP? I m able to draw a 3D Pie graph but not a line graph. My code looks as follows //The 3D bar graph # // Dataset ...

Finding cycle of 3 nodes ( or triangles) in a graph

I am working with complex networks. I want to find group of nodes which forms a cycle of 3 nodes (or triangles) in a given graph. As my graph contains about million edges, using a simple iterative ...

How to create line chart in iPhone application? [closed]

I am creating a budget application in iPhone, to budget for personal incomes and expenses. Client s need is I want to see line graph (like stock market line report). Red line for (monthly / weekly /...

热门标签