Problem of the Day
A new programming or logic puzzle every Mon-Fri

Shortest Path

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.

path graph

#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.

* Great resource to learn

Permalink: http://problemotd.com/problem/shortest-path/

Comments:

  • There are currently no comments. You can be first!

Content curated by @MaxBurstein