Time Complexity Comparison
The number of edges in a connected graph is
$$ n-1 \leq m \leq \frac{n(n-1)}{2} \approx n^2 $$
๐ ์ด๋ค ๊ทธ๋ํ์ ์ ์ ์ ๊ฐ์๋ฅผ n์ด๋ผ๊ณ ํ ๋, ์ด์์ ๊ฐ์(m)์ ๋ฒ์๋ n - 1๊ฐ์์ ๋ถํฐ n(n - 1)/2์ด๋ค. ์ฌ๊ธฐ์ n(n-1)/2์ 1๋ถํฐ n-1๊น์ง์ ํฉ์ด๋ค.
For a graph whose number of edges m is near the low end of these limits (the graph is very sparse), Kruskal’s algorithm is $\Theta(nlgn)$ which means that Kruskal's algorithm should be faster. However, for a graph whose number of edges is near the high end (the graph is highly connected), Kruskal’s algorithm is $\Theta(n^2lgn)$, which means that Prim's algorithm should be faster.
| Algorithm Technique | Time Complexity (์๊ฐ๋ณต์ก๋) |
Sparse Graph (ํฌ์ ๊ทธ๋ํ) |
Dense Graph (๋ฐ์ง ๊ทธ๋ํ) |
| Prim's Algorithm | $\Theta(n^2)$ | $\Theta(n^2)$ | $\Theta(n^2)$ |
| Kruskal's Algorithm | $\Theta(mlgm)$ and $\Theta(n^2lgn)$ | $\Theta(mlgm)$ | $\Theta(n^2lgn)$ |
๐ ์ด์์ ์ ๊ฐ์๊ฐ ํํ์ ๊ทผ์ฒ(n - 1์ ๊ทผ์ )์ธ ๊ฒฝ์ฐ ํฌ์ ๊ทธ๋ํ(sparse graph)์ด๊ณ , ์ํ์ ๊ทผ์ฒ(n(n - 1)/2์ ๊ทผ์ )์ธ ๊ฒฝ์ฐ๋ ๋ฐ์ง ๊ทธ๋ํ(dense graph) ์ด๋ค.
์์ ์ฑ๋ฅ ๋น๊ตํ์์ ์ ์ ์๋ฏ์ด, ํฌ์ ๊ทธ๋ํ์ ๊ฒฝ์ฐ Kruskal ์๊ณ ๋ฆฌ์ฆ์ ์ฑ๋ฅ์ด, ๋ฐ์ง ๊ทธ๋ํ์ ๊ฒฝ์ฐ์ Prim ์๊ณ ๋ฆฌ์ฆ์ ์ฑ๋ฅ์ด ํจ์จ์ ์์ ์ ์ ์๋ค.
