Professional Documents
Culture Documents
Diem Ha - Dijkstra's Algorithm
Diem Ha - Dijkstra's Algorithm
Diem Ha - Dijkstra's Algorithm
Dijkstra discovered this algorithm as a way to demonstrate the performance of the new ARMAC
(Automatische Rekenmachine van het Mathematisch Centrum). His responsibility was both defining a
problem and finding a solution for it, but he also had to assure that even non-computing people can
comprehend the answer.
He attempted to do this task with the Netherland map including 64 cities. Dijkstra came up with the
algorithm when he was going out with his fiancée, and that was a twenty-minute invention. Dijkstra
later attributed this success to the fact that there were not any pencil and paper when he designed this
algorithm; therefore, avoiding many complexities.
(Reference: Misa, Thomas. (2010). An Interview with Edsger W. Dijkstra. Commun. ACM. 53. 41-47.
10.1145/1787234.1787249.)
Question 2
1. General approach
From node A, I write down the distance to all other nodes, and place ∞ for unreachable nodes.
I bold the lowest distance of the row. This marks as “finished” and I will not copy down that distance
anymore.
I pick the shortest path from A to another node and copy the distance (1 A), and the node (B) to another
row.
I list the distance from B to other nodes, and calculate the sum of (distance from A to B) + (distance from
B to others)
If the result is greater than the previous number (from A to others), or the result cannot be
calculated (because B does not reach that node), I will write down the previous distance in the
new row.
If the result is less than the previous number, I will write down the new distance in the new row.
Note:
Bold number: the lowest of the row, the “finished”
Red: changed number
First, I start from A. The shortest paths from A to B, C, F are 1, 3, and 10 respectively
A B C D E F G
A 0A 1A 3A ∞ ∞ 10A ∞
Then, I pick B as the next point because 1 is the lowest (except for 0). I can see the path from A-B-C is
shorter than from A-C. So, I write 2B in the new row. Through B, I can also reach D, E, G.
A B C D E F G
A 0A 1A 3A ∞ ∞ 10A ∞
B 1A 2B 8B 6B 10A 3B
Through node C, I can get to E with the distance of 5. So, I write 5 C in the new row. Getting to D through
C is longer than through B so I keep it as the previous: 8 B
A B C D E F G
A 0A 1A 3A ∞ ∞ 10A ∞
B 1A 2B 8B 6B 10A 3B
C 2B 8B 5C 10A 3B
My next node is G because 3 is the lowest left, but G cannot improve the distance to any other nodes.
A B C D E F G
A 0A 1A 3A ∞ ∞ 10A ∞
B 1A 2B 8B 6B 10A 3B
C 2B 8B 5C 10A 3B
G 8B 5C 10A 3B
A B C D E F G
A 0A 1A 3A ∞ ∞ 10A ∞
B 1A 2B 8B 6B 10A 3B
C 2B 8B 5C 10A 3B
G 8B 5C 10A 3B
E 7E 5C 7E
The last two points, D and F do not improve the distance, so I keep it as below.
A B C D E F G
A 0A 1A 3A ∞ ∞ 10A ∞
B 1A 2B 8B 6B 10A 3B
C 2B 8B 5C 10A 3B
G 8B 5C 10A 3B
E 7E 5C 7E
D 7E 7E
F 7E
3. Conclusion