22-Elec-B4 Information Technology Networks · December 2014
Question 2 of 5: Shortest-Path Routing by Dijkstra’s Algorithm
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer) · Last updated
Notes on this paper
Reference texts. A. Leon-Garcia and I. Widjaja, Communication Networks: Fundamental Concepts and Key Architectures, 2nd ed. (the EGBC/PEO syllabus reference for this code); J. F. Kurose and K. W. Ross, Computer Networking: A Top-Down Approach, 8th ed.; A. S. Tanenbaum and D. J. Wetherall, Computer Networks, 5th ed.; T. S. Rappaport, Wireless Communications: Principles and Practice, 2nd ed.; W. Stallings, Data and Computer Communications, 10th ed.
Question 2: Shortest-Path Routing by Dijkstra’s Algorithm (25 marks)
Given. The undirected weighted graph printed with the question, read directly from the examination drawing: seven nodes and eleven edges, with the link costs tabulated below.
[Figure not reproduced: The network of Question 2. Node A is the source; edge labels are link costs. Eleven edges connect the seven nodes. See the official exam paper.]
Given data — link costs
Edge
Cost
Edge
Cost
Edge
Cost
A–B
5
C–D
1
E–F
6
A–C
1
C–E
1
E–G
1
A–D
3
C–F
2
F–G
3
B–E
2
D–F
1
Find. The least-cost path from A to each of B, C, D, E, F and G, together with its cost, obtained by an explicit execution of Dijkstra’s algorithm.
Approach. Maintain a set $N$ of nodes whose shortest distance is already known and a label $D(v)$ for every other node; at each iteration move the unlabelled node of smallest label into $N$, then relax its neighbours using $D(v) \leftarrow \min\{D(v),\, D(w) + c(w,v)\}$.
Initialise. Put the source into the permanent set, $N = \{\mathrm{A}\}$, and label every other node with its direct link cost from A, or infinity where no direct link exists: $$D(\mathrm{B}) = 5, \quad D(\mathrm{C}) = 1, \quad D(\mathrm{D}) = 3, \quad D(\mathrm{E}) = D(\mathrm{F}) = D(\mathrm{G}) = \infty.$$
Iteration 1 — absorb C. The smallest label among unlabelled nodes is $D(\mathrm{C}) = 1$, so C joins the permanent set and its neighbours are relaxed. Through C we reach D at $1 + 1 = 2$ (better than the direct 3), E at $1 + 1 = 2$, and F at $1 + 2 = 3$. Node C is a hub of cost-1 links, which is why it dominates the whole solution: $$N = \{\mathrm{A,C}\}, \quad D(\mathrm{B}) = 5, \ D(\mathrm{D}) = 2, \ D(\mathrm{E}) = 2, \ D(\mathrm{F}) = 3, \ D(\mathrm{G}) = \infty.$$
Iteration 2 — absorb D. D and E are tied at 2; the algorithm may take either, and taking D first changes nothing about the final answer. Relaxing through D offers F at $2 + 1 = 3$, which merely ties the label F already holds. Hence $$N = \{\mathrm{A,C,D}\}, \quad D(\mathrm{B}) = 5, \ D(\mathrm{E}) = 2, \ D(\mathrm{F}) = 3, \ D(\mathrm{G}) = \infty.$$
Iteration 3 — absorb E. E enters at cost 2 and is the pivotal relaxation of the problem. Through E, node B improves from 5 to $2 + 2 = 4$, so the direct A–B link is abandoned; node G is reached for the first time at $2 + 1 = 3$; and F is offered $2 + 6 = 8$, which is rejected. Thus $$N = \{\mathrm{A,C,D,E}\}, \quad D(\mathrm{B}) = 4, \ D(\mathrm{F}) = 3, \ D(\mathrm{G}) = 3.$$
Iterations 4 and 5 — absorb F, then G. F and G are tied at 3. Absorbing F offers G a route at $3 + 3 = 6$, which loses to the label of 3 that G already carries, so nothing changes; G is then absorbed at 3 and offers B nothing. $$N = \{\mathrm{A,C,D,E,F,G}\}, \quad D(\mathrm{B}) = 4.$$
Iteration 6 — absorb B and terminate. B is the last node, entering at 4. Every node is now permanent, so the algorithm halts and the labels are the true shortest-path costs: $$\boxed{D(\mathrm{B}) = 4,\ D(\mathrm{C}) = 1,\ D(\mathrm{D}) = 2,\ D(\mathrm{E}) = 2,\ D(\mathrm{F}) = 3,\ D(\mathrm{G}) = 3}$$
Tracing each node back through the predecessor that last improved its label gives the routes themselves, which together form the shortest-path tree rooted at A shown below. Two observations are worth recording for the examiner. First, the expensive A–B edge of cost 5 and the E–F edge of cost 6 are never used — every optimal route avoids them. Second, node F is reached at cost 3 by two genuinely tied routes, A–C–F and A–C–D–F; the shortest-path tree is therefore not unique, though the cost vector is.
[Figure not reproduced: The shortest-path tree rooted at A (heavy lines). The A–B and E–F edges carry no traffic; the F branch is drawn via C, the tied alternative running A–C–D–F at the same cost of 3. See the official exam paper.]