Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Worksheets related to Applied Discrete Structures

18196 views
ubuntu2004
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()
edges=[("Boston", "Concord", 75), ("Boston", "Augusta", 165), ("Augusta", "Concord", 148),("Hartford","Boston",103),("Hartford","Concord",142),("Hartford","Augusta",266),("Montpelier","Boston",192),("Montpelier","Concord",117),("Montpelier","Augusta",190),("Montpelier","Hartford",204),("Providence","Boston",43),("Providence","Concord",109),("Providence","Augusta",208),("Providence","Hartford",70),("Providence","Montpelier",223)] 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
[('Boston', 'Providence', 43), ('Hartford', 'Providence', 70), ('Boston', 'Concord', 75), ('Concord', 'Montpelier', 117), ('Augusta', 'Concord', 148)]
T.set_pos(G.get_pos()) Graph(E).graphplot(edge_labels=True).show()
import sage.graphs.spanning_tree
graphs.spanning_tree.
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python3.11/site-packages/smc_sagews/sage_server.py", line 1245, in execute compile(block + '\n', File "<string>", line 1 graphs.spanning_tree. ^ SyntaxError: invalid syntax
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()