《演算法(英文版·第4版)》勘誤(第621頁)

黃志斌發表於2013-03-21

AlgorithmsEng

《演算法(英文版·第4版)》第 621 頁:

Prim01

It builds the MST as follows:

  • Adds 0 to the MST and all edges in its adjacency list to the priority queue, since each such edge is the best (only) known connection between a tree vertex and a non-tree vertex.
  • Adds 7 and 0-7 to the MST and 1-7 and 5-7 to the priority queue. Edges 4-7 and 2-7 do not affect the priority queue because their weights are not less than the weights of the known connections from the MST to 4 and 2, respectively.
  • Adds 1 and 1-7 to the MST and 1-3 to the priority queue.
  • Adds 2 and 0-2 to the MST, replaces 0-6 with 2-6 as the shortest edge from a tree vertex to 6, and replaces 1-3 with 2-3 as the shortest edge from a tree vertex to 3.
  • Adds 3 and 2-3 to the MST.
  • Adds 5 and 5-7 to the MST and replaces 0-4 with 4-5 as the shortest edge from a tree vertex to 4.
  • Adds 4 and 4-5 to the MST.
  • Adds 6 and 6-2 to the MST.

After having added V-1 edges, the MST is complete and the priority queue is empty.


上面的圖和文字說明都有錯誤,修改如下:

Prim02

It builds the MST as follows:

  • Adds 0 to the MST and all edges in its adjacency list to the priority queue, since each such edge is the best (only) known connection between a tree vertex and a non-tree vertex.
  • Adds 7 and 0-7 to the MST and 1-7 and 5-7 to the priority queue. Replace 0-4 with 4-7 as the shortest edge from a tree vertex to 4, and 2-7 do not affect the priority queue because its weight is not less than the weight of 0-2.
  • Adds 1 and 1-7 to the MST and 1-3 to the priority queue.
  • Adds 2 and 0-2 to the MST, replaces 6-0 with 6-2 as the shortest edge from a tree vertex to 6, and replaces 1-3 with 2-3 as the shortest edge from a tree vertex to 3.
  • Adds 3 and 2-3 to the MST.
  • Adds 5 and 5-7 to the MST and replaces 4-7 with 4-5 as the shortest edge from a tree vertex to 4.
  • Adds 4 and 4-5 to the MST.
  • Adds 6 and 6-2 to the MST.

After having added V-1 edges, the MST is complete and the priority queue is empty.


上面是使用即時 Prim 演算法來計算示例加權圖的最小生成樹的軌跡。這個示例加權圖及其最小生成樹如下所示:

tinyEWG1

它的鄰接表表示如下所示:

tineyEWG2

相關文章