22-Elec-B4 Information Technology Networks · December 2017
Question 4 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. Engineers Canada / Professional Engineers of Ontario, National Examinations — December 2017, 16-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, and the marks are printed in the left margin against every sub-part. All five questions are solved here, because this set is a study resource rather than an exam attempt.
Reference texts.
A. Leon-Garcia and I. Widjaja, Communication Networks: Fundamental Concepts and Key Architectures, 2nd ed., McGraw-Hill — the syllabus text for this paper (layering, transport, routing, switching).
J. F. Kurose and K. W. Ross, Computer Networking: A Top-Down Approach, 8th ed., Pearson — IP forwarding tables, TCP congestion control, packet versus circuit switching.
A. S. Tanenbaum and D. J. Wetherall, Computer Networks, 5th ed., Pearson — the OSI reference model and the TCP/IP layer stack.
D. Bertsekas and R. Gallager, Data Networks, 2nd ed., Prentice-Hall — shortest-path routing and Dijkstra's algorithm.
Canadian context. The addressing and numbering practice assumed throughout is the Canadian one: IPv4 and IPv6 blocks used by Canadian networks are allocated by ARIN, of which Canada is part, and the national research network CANARIE has run production IPv6 since the mid-2000s, which is why the IPv6 answer in Question 1(c) is the operational rather than the theoretical response. Circuit-switched telephony in Question 5 refers to the Canadian PSTN as regulated by the CRTC.
Question 4: Shortest-Path Routing by Dijkstra's Algorithm (25 marks)
[Figure not reproduced: Figure 4.1 — The network of Question 4, redrawn from the examination paper: seven nodes and ten undirected edges with the printed distances. Node F is the source. See the official exam paper.]
Given. An undirected graph on the node set {A, B, C, D, E, F, G} with ten edges and non-negative lengths:
Edge
A–B
A–C
A–D
B–E
C–D
C–F
D–F
E–F
E–G
F–G
Length
1
2
2
5
1
2
1
1
1
3
Source node F, whose neighbours are C (2), D (1), E (1) and G (3).
Find. The shortest distance and the shortest path from F to each of A, B, C, D, E and G, obtained by Dijkstra's algorithm with the work shown at every iteration.
Approach. Maintain a set $N$ of nodes whose distance is final and a tentative label $D(v)$ for every other node; at each iteration move the unlabelled node of smallest tentative distance into $N$, then relax every edge out of it, recording the predecessor whenever a label improves.
Initialise from the source. Set $D(\text{F}) = 0$ and $N = \{\text{F}\}$. Every neighbour of F takes the length of its direct edge and every other node takes infinity:
Iteration 1 — add D. The smallest tentative label is 1, held by both D and E; ties may be broken arbitrarily and D is taken first. With $D(\text{D}) = 1$ made permanent, relax D's edges: A improves from $\infty$ to $1 + 2 = 3$ with predecessor D, and C is offered $1 + 1 = 2$, which merely ties its existing label of 2, so no change is recorded. This tie is real and is worth stating in the answer: F–C and F–D–C are both of length 2.
Iteration 2 — add E. The smallest remaining label is 1 at E. Relaxing E's edges gives B its first finite label, $1 + 5 = 6$ with predecessor E, and improves G from 3 to $1 + 1 = 2$ with predecessor E — the two-hop route F–E–G beats the direct edge F–G of length 3.
Iterations 3 and 4 — add C, then G. Both now carry the label 2. Making C permanent offers A the value $2 + 2 = 4$, which does not beat the existing 3, so nothing changes; making G permanent offers nothing new, since both of its neighbours are already permanent. Neither iteration alters a label, which is the normal behaviour once the frontier has passed a node.
Iteration 5 — add A. The smallest remaining label is 3 at A. Relaxing A's edges improves B from 6 to $3 + 1 = 4$, with predecessor A: the long direct edge B–E of length 5 is beaten by going the long way round through D and A.
Iteration 6 — add B, and the algorithm terminates. B enters with 4 and $N$ now contains all seven nodes, so every label is final. Collecting the work into one table, where a dash marks a node already made permanent:
Iteration
Node added (final $D$)
$D(\text{A})$
$D(\text{B})$
$D(\text{C})$
$D(\text{D})$
$D(\text{E})$
$D(\text{G})$
Init
F (0)
$\infty$
$\infty$
2 (F)
1 (F)
1 (F)
3 (F)
1
D (1)
3 (D)
$\infty$
2 (F)
—
1 (F)
3 (F)
2
E (1)
3 (D)
6 (E)
2 (F)
—
—
2 (E)
3
C (2)
3 (D)
6 (E)
—
—
—
2 (E)
4
G (2)
3 (D)
6 (E)
—
—
—
—
5
A (3)
—
4 (A)
—
—
—
—
6
B (4)
—
—
—
—
—
—
The letter in brackets is the predecessor recorded with each label, which is what turns the distances into paths.
Read the paths off the predecessors. Following each predecessor back to F gives the routes, and their lengths reproduce the final labels exactly:
The six predecessor edges form the shortest-path tree rooted at F, of total weight $1 + 1 + 2 + 2 + 1 + 1 = 8$; this tree, not the distance list, is what a router would install as its forwarding state.
Figure 4.2 — The shortest-path tree rooted at F drawn heavy over the original graph: F–C, F–D, F–E, D–A, A–B and E–G. The unused edges A–C, C–D, B–E and F–G are shown thin.
Sanity-check the result. Three checks cost nothing and catch the usual slips. The tree has six edges for six non-source nodes and no cycle, as any shortest-path tree must; the two edges the algorithm rejected are each demonstrably worse than the route chosen, since B–E offers B a length of $1+5 = 6$ against the 4 actually found and F–G offers G a length of 3 against the 2 actually found; and every label is non-decreasing in the order the nodes were made permanent (0, 1, 1, 2, 2, 3, 4), which is the property that makes Dijkstra's greedy choice valid on non-negative weights.