Djikstra's Algorithm
We can't all be graph theory geniuses like my friend Nathan Klein, but...we can learn how to make graphs in JavaScript.
Source: Wikipedia
Quite often, we need to find the shortest path from one node to another (such as in the Traveling Salesman problem. It's a great problem). What's the best way to do that? Djikstra's algorithm.
Dijkstra’s algorithm has a Big O complexity of log n, which is super efficient. How does one do Djikstra's algorithm? It's simple: you start at one node, and then move to the next node that has the shortest distance. Once you're there, you again consider, from each node you've visited, what the shortest remaining node is. You mark that one as visited, and continue the process until you've hit your target node.
[removed]
Comments
Post a Comment