Some of the more advanced theories in computer science revolve around graph theory. One such application of graph theory is finding the shortest point between two points. A famous computer scientist developed a path finding algorithm known as Dijkstra's Algorithm. Today's goal is to implement his algorithm to find the shortest path between A and H.
#Example building graph in Python g = Graph() g.add_vertex('A', {'B': 7, 'C': 8}) g.add_vertex('B', {'A': 7, 'F': 2}) g.add_vertex('C', {'A': 8, 'F': 6, 'G': 4}) g.add_vertex('D', {'F': 8}) g.add_vertex('E', {'H': 1}) g.add_vertex('F', {'B': 2, 'C': 6, 'D': 8, 'G': 9, 'H': 3}) g.add_vertex('G', {'C': 4, 'F': 9}) g.add_vertex('H', {'E': 1, 'F': 3}) print(g.shortest_path('A', 'H'))
For bonus points submit your algorithm to https://github.com/mburst/dijkstras-algorithm.
Comments: