Empirical Study on Finding Minimal Spanning Tree S. J. Shyu 4/29/2012
演算法 6-5 Kruskal 演算法求最小延展樹 輸入:加權圖形 G = ( V, E ) , | V |= n ; w ( e ) 為邊 e 上的權重值 輸出: T , T 為 G 的最小延展樹 1 T = ; 2 while (( T 中少於 n 1 條邊 ) && ( E != )) 3 { ( u, v ) = E 中最小權重的邊 ; 4 E = E \{( u, v )} ; 5 if (( u, v ) 加入 T 後不致形成迴圈 ) 6 T = T {( u, v )} ; 7 } 8 if ( T 中邊數 <( n 1)) 印出 ” G 無延展樹! ”; 9 else 輸出 T ; using Loop using Heap using Loop using Union&Find
Questions What are the performances of Kruskal’s algorithm when selecting min. by loop vs. by heap? What are the performances of Kruskal’s algorithm when detecting cycles by loop vs. by union-find?
Experiments CPU: Intel Core i GHz RAM: 4GB OS: Windows 7 Program: BCB 2010
Comparison of Selecting Min. by Loop and Heap in Kruskal’s Algorithm 2% 9% 18%29% 44%90% 1%
Remarks In Kruskal’s algorithm, selecting min. by heap is better than by loop? The superiority of using heap (over loop) grows as %edge increases. – Problems with more edges receive more benefit when using heap (than loop). Detecting cycles by union-find outperforms those by loop? The superiority of using union-find (over loop) grows as %edge decreases. – When %edge decreases, the edges incurring cycles grows so that union-find conquers loop for cycle detection.
Question What are the performances of Kruskal’s and Prim’s algorithms?
Remarks The performance of Prim’s algorithm is robust w.r.t. all kinds of problem instances. The execution time of Kruskal’s algorithm decreases as %edge decreases. Apply Prim’s algorithm when %edge is large, say >0.1 for |V|=10000; whereas Kruskal’s, otherwise.
Programs = Data Structures + Algorithms