NivaarExam PrepOfficial exam papers ↗

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)

Notes on this paper

Paper format. Professional Engineers of Ontario Annual Examinations, December 2014 — 07-Elec-B4 Information Technology Networks. Three hours, closed book, a PEO-approved non-programmable calculator permitted. Five questions of 25 marks each; any four constitute a complete paper worth 100 marks, with marks noted in the left margin. Candidates are urged to state any interpretive assumptions with their answers. All five questions are worked below, since the complete set is more useful as a study resource than any four of it.

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)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

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.

51321121613ABCDEFG
The network of Question 2. Node A is the source; edge labels are link costs. Eleven edges connect the seven nodes.
Given data — link costs
EdgeCostEdgeCostEdgeCost
A–B5C–D1E–F6
A–C1C–E1E–G1
A–D3C–F2F–G3
B–E2D–F1

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)\}$.

  1. 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.$$
  2. 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.$$
  3. 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.$$
  4. 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.$$
  5. 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.$$
  6. 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.

51321121613ABCDEFG
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.
Question 2 — shortest paths from A
DestinationLeast-cost pathCostNext hop from A
BA–C–E–B4C
CA–C1C
DA–C–D2C
EA–C–E2C
FA–C–F or A–C–D–F3C
GA–C–E–G3C