7.21. Dijkstra算法分析¶
7.21. Analysis of Dijkstra’s Algorithm
最后,让我们来看看 Dijkstra 算法的运行时间。我们首先注意到,构建优先队列需要 while
循环会对每个节点执行一次,因为节点在开始时都已添加,并且之后才会被移除。在这个循环中,每次调用 delete
需要 delete
的时间复杂度是 for
循环对图中的每条边执行一次,而在 for
循环中,调用 change_priority
需要
Finally, let’s look at the running time of Dijkstra’s algorithm. We first note that building the priority queue takes while
loop is executed once for every vertex since vertices are all added at the beginning and only removed after that. Within that loop each call to delete
takes delete
take for
loop is executed once for each edge in the graph, and within the for
loop the call to change_priority
takes
创建日期: 2024年9月9日