Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - Floyd-Warshall
Search - Floyd-Warshall - List
Floyd-Warshall算法描述 1)适用范围: a)APSP(All Pairs Shortest Paths) b)稠密图效果最佳 c)边权可正可负 2)算法描述: a)初始化:dis[u,v]=w[u,v] b)For k:=1 to n For i:=1 to n For j:=1 to n If dis[i,j]>dis[i,k]+dis[k,j] Then Dis[I,j]:=dis[I,k]+dis[k,j] c)算法结束:dis即为所有点对的最短路径矩阵 3)算法小结:此算法简单有效,由于三重循环结构紧凑,对于稠密图,效率要高于执行|V|次Dijkstra算法。时间复杂度O(n^3)。 考虑下列变形:如(I,j)∈E则dis[I,j]初始为1,else初始为0,这样的Floyd算法最后的最短路径矩阵即成为一个判断I,j是否有通路的矩阵。更简单的,我们可以把dis设成boolean类型,则每次可以用“dis[I,j]:=dis[I,j]or(dis[I,k]and dis[k,j])”来代替算法描述中的蓝色部分,可以更直观地得到I,j的连通情况。 -err
Date : 2025-12-25 Size : 3kb User : 江晨

图的基类以及最短路径算法,dijkstra,floyd,Kruskal算法等,代码来自北大赵海燕老师编著的数据结构与算法。-Graph base class as well as the shortest path algorithm, dijkstra, floyd, Kruskal algorithm, code Zhao Haiyan teachers from Beijing University and edited by the data structure and algorithm.
Date : 2025-12-25 Size : 648kb User : 张淼
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.