Sharedsage_worksheets / Kruskal.sagewsOpen in CoCalc
Author: Ken Levasseur
Description: Worksheets related to Applied Discrete Structures
edges=[(1, 2, 4), (2, 8, 4), (3, 8, 4), (4, 7, 5), (6, 8, 5), (1, 3, 6), (1, 7, 6), (4, 5, 6), (5, 10, 9), (2, 10, 7), (4, 6, 7), (2, 4, 8), (1,8, 9), (1, 9, 9), (5, 6, 9), (1, 10, 10), (2, 9, 10), (4, 9, 10), (5, 9, 10), (6, 9, 10)] G=Graph(edges) G.weighted(True) G.graphplot(edge_labels=True,save_pos=True).show()
from sage.graphs.spanning_tree import kruskal E = kruskal(G, check=True);E
[(1, 2, 4), (1, 7, 6), (1, 9, 9), (2, 8, 4), (2, 10, 7), (3, 8, 4), (4, 5, 6), (4, 7, 5), (6, 8, 5)]
T=Graph(E) T.set_pos(G.get_pos()) T.graphplot(edge_labels=True).show()