Kruskal’s Algorithm in C — Minimum Spanning Tree with Union-Find

Kruskal’s algorithm finds the minimum spanning tree (MST) of a weighted, connected, undirected graph — the cheapest possible set of edges that connects every vertex with no cycles. It’s the classic greedy approach: sort all edges by weight, then keep taking the cheapest edge that doesn’t form a cycle. Road networks, electrical wiring, and network …

Prim’s Algorithm in C – Minimum Spanning Tree (MST)

Prim’s algorithm finds the Minimum Spanning Tree (MST) of a weighted undirected graph — the set of edges that connects all vertices at the lowest possible total cost. It works by growing a single tree: start at any vertex, then repeatedly add the cheapest edge that reaches a vertex not yet in the tree, until …