MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / krusk

Function krusk

graphs/basic_graphs.py:350–371  ·  view source on GitHub ↗

Sort edges on the basis of distance

(e_and_n)

Source from the content-addressed store, hash-verified

348
349
350def krusk(e_and_n):
351 """
352 Sort edges on the basis of distance
353 """
354 (e, n) = e_and_n
355 e.sort(reverse=True, key=lambda x: x[2])
356 s = [{i} for i in range(1, n + 1)]
357 while True:
358 if len(s) == 1:
359 break
360 print(s)
361 x = e.pop()
362 for i in range(len(s)):
363 if x[0] in s[i]:
364 break
365 for j in range(len(s)):
366 if x[1] in s[j]:
367 if i == j:
368 break
369 s[j].update(s[i])
370 s.pop(i)
371 break
372
373
374def find_isolated_nodes(graph):

Callers

nothing calls this directly

Calls 3

sortMethod · 0.80
popMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected