박권수

feature1.0.1

import numpy
import numpy as np
#Kruskal Algorithm
parent = dict()
rank = dict()
def make_singleton_set(v) :
parent[v] = v
rank[v] = v
rank[v] = 1
def find(v) :
if(parent[v] != v) :
......@@ -31,4 +32,36 @@ def Kruskal(graph) :
edge_list = list(graph['edges'])
edge_list.sort()
F = []
\ No newline at end of file
F = set()
index = 0
while len(F) < n - 1 :
e = edge_list[index]
p = find(e[1])
q = find(e[2])
if(p == q) :
union(p, q)
F.add(e)
index += 1
return F
graph = {
'vertices': ['A', 'B', 'C', 'D', 'E'],
'edges': set([
(1, 'A', 'B'),
(3, 'A', 'C'),
(3, 'B', 'C'),
(6, 'B', 'D'),
(4, 'C', 'D'),
(2, 'C', 'E'),
(5, 'D', 'E'),
])
}
for i in range(0, 5) :
make_singleton_set(i)
mst = Kruskal(graph)
print(mst)
\ No newline at end of file
......