Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Complete Graph

(n² edges to consider)

A complete graph is a graph where every pair of nodes has an edge. With nn nodes, you have n(n1)2\frac{n(n-1)}{2} edges. For this problem, generating all edges upfront takes O(n2)O(n^2) time and space. That is acceptable for small nn (up to 10001000).

Kruskal still works, but you will spend time sorting O(n2)O(n^2) edges. Prim might be faster here because it does not require generating all edges upfront. Think about the tradeoff.