Skip to content

Commit 4a499f6

Browse files
Add Kruskal pseudo-code
1 parent b062050 commit 4a499f6

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Pseudocode/Graph/kruskal.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Node = int
2+
using Weight = int
3+
4+
vector<pair<pair<<Node, Node>>, Weight> edge_list
5+
ranges::sort(edge_list, [](const auto& a, const auto& b) { return a.second < b.second});
6+
7+
UFDS ufds(num_vertices);
8+
9+
cost = 0
10+
11+
for (auto[w, uv] : edge_list) {
12+
auto[u, v] = uv;
13+
if(!ufds.IsSameSet(u, v)) {
14+
cost += w
15+
ufds.Union(u, v)
16+
}
17+
}
18+
19+
return cost;

0 commit comments

Comments
 (0)