Dijkstra's algorithm: Difference between revisions

m
added whitespace before the TOC (table of contents), added a Task and Extra Credit (bold) headers.
(Added directed/undirected option to Lua version)
m (added whitespace before the TOC (table of contents), added a Task and Extra Credit (bold) headers.)
Line 1:
{{draft task|Classic CS problems}}{{Wikipedia pre 15 June 2009| pagename=Dijkstra's algorithm| lang=en| oldid=295012245| timedate=17:56, 7 June 2009‎‎}}
 
<br>
'''Dijkstra's algorithm''', conceived by Dutch computer scientist [[wp:Edsger Dijkstra|Edsger Dijkstra]] in 1956 and published in 1959, is a [[wp:graph search algorithm|graph search algorithm]] that solves the single-source [[wp:shortest path problem|shortest path problem]] for a [[wp:graph (mathematics)|graph]] with nonnegative [[wp:edge (graph theory)|edge]] path costs, producing a [[wp:shortest path tree|shortest path tree]]. This algorithm is often used in [[wp:routing|routing]] and as a subroutine in other graph algorithms.
 
For a given source [[wp:vertex (graph theory)|vertex]] (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network [[wp:routing protocol|routing protocol]]s, most notably [[wp:IS-IS|IS-IS]] and [[wp:OSPF|OSPF]] (Open Shortest Path First).
 
 
''';Task:'''
# Implement a version of Dijkstra's algorithm that computes a shortest path from a start vertex to an end vertex in a directed graph.
# Run your program with the following directed graph to find the shortest path from vertex "a" to vertex "e."
Line 50 ⟶ 53:
You can use numbers or names to identify vertices in your program.
 
 
'''Extra Credit:''' Document the specific algorithm implemented. The <nowiki>{{trans}}</nowiki> template is sufficient. Otherwise add text outside of your program or add comments within your program. This is not a requirement to explain ''how'' the algorithm works, but to state ''which'' algorithm is implemented. If your code follows an external source such as the Wikipedia pseudocode, you can state that. You can state if it is Dijkstra's original algorithm or some more efficient variant. It is relevant to mention things like priority queues, heaps, and expected time complexity in big-O notation. If a priority queue is used, it is important to discuss how the step of decreasing the distance of a node is accomplished, and whether it is linear or logarithmic time.
;Extra Credit:
'''Extra Credit:''' Document the specific algorithm implemented. The <nowiki>{{trans}}</nowiki> template is sufficient. Otherwise add text outside of your program or add comments within your program. This is not a requirement to explain ''how'' the algorithm works, but to state ''which'' algorithm is implemented. If your code follows an external source such as the Wikipedia pseudocodepseudo-code, you can state that. You can state if it is Dijkstra's original algorithm or some more efficient variant. It is relevant to mention things like priority queues, heaps, and expected time complexity in big-O notation. If a priority queue is used, it is important to discuss how the step of decreasing the distance of a node is accomplished, and whether it is linear or logarithmic time.
<br><br>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - one minor extension to language used - PRAGMA READ, similar to C's #include directive.}}