English 中文(简体)
Dijkstra诉Flinoyd-Warshall: 寻找所有奶牛的最佳途径
原标题:Dijkstra vs. Floyd-Warshall: Finding optimal route on all node pairs

我正在阅读Dijkstra的算法和Flinoyd-Warshall的算法。 我的理解是,Dijkstra认为,从一线到所有其他节点的最佳途径,Flinoyd-Warshall为所有 no子的最佳途径。

我的问题是Dijkstra的算法,如果我把算法放在每一个单项 no子上,以便找到所有奶制品之间的最佳途径,则其效率要高于Flinoyd。

Dijkstra 运行时间为O(E + VlogV),Flinoyd s为O(V3)。 如果Dijkstra失败,那么本案的运行时间会是什么? 感谢!

问题回答

正如其他人所指出的,Flinoyd-Warshall在O(n3)时间上运行,从每条 no到另一条 no,假定你利用Fibonacci的肥皂支持执行Dijkstra,从O(mn + n2. n)。 然而,由于Dijkstra的算法没有带有负面的权重,你不能总是安全地将Dijkstra置于任意的图表之上。

Johnson setic=>,这是对从每一节点开始Dijkstra算法的细微改动,即使图表含有消极的对冲(只要有斜线)。 该算法首先运行Bellman-Ford,在图表上将其转换成一个没有消极面的图表,然后使用Dijkstra的算法,从每个透镜开始。 由于Belman-Ford在时间O(mn)上运行,因此,总体的症状管理时间为O(mn + n2log n),因此,如果m = o(n2)。 (请注意:little-o of n),这一办法比使用Flinoyd-Warshall更快。

这里的捕获量是,这假设你有Dijkstra的算法,由Fibonacci的得分支撑。 如果你没有Pafbonacci的肥皂,愿意在建造、洗浴和测试所需的72小时内投入使用,那么,你仍可以使用双双双双双双双双双双双双向的吉克平方算法;它只是将操作时间提高到O(mlog n),因此,Johnson这一算法在O(mnlog n)运行。 这已不再总是比Flinoyd-Warshall更快,因为如果m = Ω(n2),则Flinoyd-Warshall在O(n3)上运行,而Johnson的算法则在O(n 3log n)上运行。 然而,对于小graph的图表,即m = o(n2/log n),执行约翰逊算法的情况仍然比Floyd-Warshall好。

简言之:

  • With a Fibonacci heap, Johnson s algorithm is always asymptotically at least as good as Floyd-Warshall, though it s harder to code up.
  • With a binary heap, Johnson s algorithm is usually asymptotically at least as good as Floyd-Warshall, but is not a good option when dealing with large, dense graphs.

希望这一帮助!

在所有节点上运行Dijkstra的复杂性是O(EV + V2logV)。 这种复杂性低于O(V3)。 iff E < V2

它取决于。 对所有节点都采用Dijkstra,给您<代码>O(VE + V^2log V),而Flinoyd s则是O(V^3)。 如果E = O(V^2),则两者在理论上相同,Flinoyd在实际中较快。 如果您E = O(V),那么,如果在理论和实践上都更好的话,所有节点都会使用Dijkstra。

基本上,如果你预计会像你所知道的那样,从所有节点中排出Dijkstra,如果你预计有几乎完整的图表,则从Flinoyd。





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签