def main(): vertex = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] edges = [('a', 'b', 4), ('a', 'h', 8), ('b', 'c', 7), ('c', 'd', 7), ('d', 'e', 9), ('e', 'f', 10), ('f', 'g', 2), ('g', 'h', 1), ('h', 'i', 7), ('g', 'i', 6), ('i', 'c', 2), ('f', 'c', 4)] graph = initGraph(vertex, edges) print(kruskal(graph))
def main(): vertex = ['s', 't', 'y', 'x', 'z'] edges = [('s', 't', 6), ('s', 'y', 7), ('t', 'x', 5), ('x', 't', -2), ('t', 'z', -4), ('y', 'z', 9), ('y', 'x', -3), ('z', 'x', 7), ('z', 's', 2), ('t', 'y', 8)] G = initGraph(vertex, edges) bellmanFord(G, 's') for v in G.V: print(G.V[v].d)
def main(): vertex = ['s', 't', 'y', 'x', 'z'] edges = [('s', 't', 10), ('s', 'y', 5), ('t', 'x', 1), ('y', 'z', 2), ('y', 'x', 9), ('z', 'x', 6), ('z', 's', 72), ('t', 'y', 2), ('t', 'y', 2), ('y', 't', 3)] G = initGraph(vertex, edges) dijkstra(G, 's') for v in G.V: print(G.V[v].d)
def main(): vertex = ['r', 's', 't', 'y', 'x', 'z'] edges = [('r', 's', 5), ('r', 't', 3), ('s', 'x', 6), ('s', 't', 2), ('t', 'y', 4), ('t', 'z', 2), ('t', 'x', 7), ('x', 'y', -1), ('x', 'z', 1), ('y', 'z', -2)] G = initGraph(vertex, edges) noCircle(G, 's') for v in G.V: print(G.V[v], G.V[v].d)