我很困惑爲什麼最短路徑的拓撲排序是O(V + E)的Big-O。 下面是算法: 1. Topologically sort G into L;
2. Set the distance to the source to 0;
3. Set the distances to all other vertices to infinity;
4. For each vertex u in L
5.
我在程序中實現這個僞代碼,以檢查是否有向圖是非循環: L ← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges
while S is non-empty do
remove a node n from S
add n to tail of