简体   繁体   English

Dijkstra算法在由排序列表/数组实现的优先级队列上的运行时间

[英]Running time for Dijkstra's algorithm on a priority queue implemented by sorted list/array

So I'm curious to know what the running time for the algorithm is on on priority queue implemented by a sorted list/array. 因此,我很想知道算法的运行时间在由排序列表/数组实现的优先级队列上。 I know for an unsorted list/array it is O((n^2+m)) where n is the number of vertices and m the number of edges. 我知道对于未排序的列表/数组,它是O((n ^ 2 + m)),其中n是顶点数,m是边数。 Thus that equates to O(n^2) time. 因此,这等于O(n ^ 2)时间。 But would it be faster if i used an sorted list/array...What would the running time be? 但是如果我使用排序列表/数组会更快吗?运行时间是多少? I know extractmin would be constant time. 我知道extractmin将是恒定的时间。

Well, Let's review what we need for dijkstra's algorithm(for future reference, usually vertices and edges are used as V and E, for example O(VlogE)): 好吧,让我们回顾一下dijkstra算法的需求(供以后参考,通常将顶点和边用作V和E,例如O(VlogE)):
Merging together all the sorted adjacency lists: O(E) 合并所有排序的邻接表:O(E)
Extract Minimum : O(1) 最低提取量:O(1)
Decrease Key : O(V) 降低键:O(V)
Dijkstra uses O(V) extract minimum operations, and O(E) decrease key operations, therefore: Dijkstra使用O(V)提取最小运算,而O(E)减少关键运算,因此:
O(1)*O(V) = O(V) O(1)* O(V)= O(V)
O(E)*O(V) = O(EV) = O(V^2) O(E)* O(V)= O(EV)= O(V ^ 2)
Taking the most asymptotically significant portion: 采取最渐近的重要部分:
Eventual asymptotic runtime is O(V^2). 最终渐近运行时间为O(V ^ 2)。
Can this be made better? 可以做得更好吗? Yes. 是。 Look into binary heaps, and better implementations of priority queues. 研究二进制堆,以及优先级队列的更好实现。

Edit : I actually made a mistake, now that I look at it again. 编辑 :我实际上犯了一个错误,现在我再看一次。 E cannot be any higher than V^2, or in other words E = O(V^2). E不能高于V ^ 2,换句话说,E = O(V ^ 2)。
Therefore, in the worst case scenario, the algorithm that we concluded runs in O(EV) is actually O(V^2 * V) == O(V^3) 因此,在最坏的情况下,我们得出的以O(EV)运行的算法实际上是O(V ^ 2 * V)== O(V ^ 3)

我使用SortedList http://blog.devarchive.net/2013/03/fast-dijkstras-algorithm-inside-ms-sql.html它比每次对List排序一次要快20到50倍

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM