22-Elec-B4 Information Technology Networks · May 2013
Question 3 of 6: 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
examination, 07-Elec-B4 Information Technology Networks, May 2013. Three
hours, closed book, one PEO-approved non-programmable calculator. Marks are shown
in the left margin of the original paper; the cover page states that four questions
constitute a complete paper worth 100 marks. Every question and every sub-part is
answered below, because the set is intended as a study resource rather than as a
sat examination.
Check: question count. The cover page of
the paper says “There are 5 questions on this exam. Any 4 questions constitute
a complete paper”, yet six numbered questions are printed (Questions 1 to 5 at
25 marks each on pages 2 to 4, and Question 6 at 20 marks on page 5), for 145 marks
in total. Four 25-mark questions do give exactly the stated 100 marks, so the cover
note is consistent with the five 25-mark questions and Question 6 appears to be a
carry-over that the cover page was never updated for. All six are solved here.
Reference texts. A. Leon-Garcia and I. Widjaja,
Communication Networks: Fundamental Concepts and Key Architectures, 2nd ed.
— the reference listed by the EGBC/Engineers Canada syllabus for this
examination 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.; W. Stallings, Data and Computer Communications,
10th ed. Normative documents cited: RFC 791 and RFC 8200 (IPv4 and IPv6), RFC 1918
and RFC 4193 (private address space), RFC 5681 (TCP congestion control), IEEE
802.3 (CSMA/CD) and IEEE 802.11 (RTS/CTS).
Question 3: Shortest-path routing by Dijkstra’s algorithm (25 marks)
Given. The seven-node undirected network printed with the
question, whose ten edges carry the distances read from the figure and listed below.
The source node is B.
Given data — edge distances read from the examination figure
Edge
Distance
Edge
Distance
A–B
1
C–F
2
A–C
2
D–F
1
A–D
2
E–F
1
B–E
5
E–G
1
C–D
1
F–G
3
Find. The least-cost path and its total distance from B to each of
A, C, D, E, F and G, showing the label state after every iteration of the algorithm.
[Figure not reproduced: Figure 3.1 — the network of Question 3, redrawn from the examination paper. Edge labels are the given link distances; node B (highlighted) is the source. See the official exam paper.]
Approach. Maintain a set $N'$ of nodes whose least cost from
B is already known and a tentative label $D(v)$ for every other node; at each
iteration move the unlabelled node of smallest label into $N'$ and relax the edges
leaving it, repeating until all seven nodes are in $N'$.
Initialise the labels. Put $N' = \{B\}$ and $D(B) = 0$. Every
neighbour of B takes the direct edge cost and every other node takes infinity:
$$D(A) = 1, \quad D(E) = 5, \quad D(C) = D(D) = D(F) = D(G) = \infty$$
The predecessor of A and of E is B; the others have none yet.
Iteration 1: absorb A. The smallest label outside $N'$ is
$D(A) = 1$, so $N' = \{B, A\}$. Relaxing the edges out of A,
$$D(C) = \min(\infty,\ 1 + 2) = 3, \qquad D(D) = \min(\infty,\ 1 + 2) = 3$$
both by way of A, while $D(E)$ stays at 5 because A does not touch E.
Iteration 2: absorb C. C and D are tied at 3; the algorithm may
break the tie either way and C is taken first. With $N' = \{B, A, C\}$, relaxing the
edges out of C offers $D(D) = \min(3,\ 3+1) = 3$, unchanged, and
$$D(F) = \min(\infty,\ 3 + 2) = 5 \text{ by way of } C$$
Iteration 3: absorb D. $D(D) = 3$ is now the smallest label
outside $N'$, giving $N' = \{B, A, C, D\}$. The edge D–F costs only 1, so
$$D(F) = \min(5,\ 3 + 1) = 4 \text{ by way of } D$$
This is the step that repays the bookkeeping: the first route found to F, through C,
cost 5, and it is displaced by a cheaper one found two iterations later.
Iteration 4: absorb F. With $D(F) = 4$ the set becomes
$N' = \{B, A, C, D, F\}$. Relaxing out of F gives
$$D(E) = \min(5,\ 4 + 1) = 5, \qquad D(G) = \min(\infty,\ 4 + 3) = 7$$
so E is tied at 5 between the direct edge B–E and the path B–A–D–F–E; the
existing predecessor B is kept.
Iteration 5: absorb E, then G. $D(E) = 5$ enters $N'$ and the
edge E–G, of cost 1, improves G:
$$D(G) = \min(7,\ 5 + 1) = 6 \text{ by way of } E$$
G then enters $N'$ at 6 and the algorithm halts with all seven nodes labelled. Note
that the cheap E–G edge is only usable once E itself is reached, which is why the
expensive direct edge B–E of cost 5 still ends up on the tree.
Read off the tree and the paths. Following predecessors back to
B gives
$$\boxed{B\!-\!A = 1,\ B\!-\!A\!-\!C = 3,\ B\!-\!A\!-\!D = 3,\ B\!-\!A\!-\!D\!-\!F = 4,\ B\!-\!E = 5,\ B\!-\!E\!-\!G = 6}$$
The six tree edges B–A, A–C, A–D, D–F, B–E and E–G total
$1+2+2+1+5+1 = 12$, and a tree on seven nodes must have six edges, which is a
useful arithmetic check on the work.
The full label history is collected below; each row is the state of the tentative
labels at the end of one iteration, with a bracketed predecessor, and a bold entry
marks the node absorbed into $N'$ at the start of the next iteration.
Dijkstra tableau — tentative labels D(v) and predecessors, source B
Step
N′
D(A)
D(C)
D(D)
D(E)
D(F)
D(G)
0
B
1 (B)
∞
∞
5 (B)
∞
∞
1
B, A
—
3 (A)
3 (A)
5 (B)
∞
∞
2
B, A, C
—
—
3 (A)
5 (B)
5 (C)
∞
3
B, A, C, D
—
—
—
5 (B)
4 (D)
∞
4
B, A, C, D, F
—
—
—
5 (B)
—
7 (F)
5
B, A, C, D, F, E
—
—
—
—
—
6 (E)
6
all seven
—
—
—
—
—
—
Figure 3.2 — the shortest-path tree rooted at B produced by Dijkstra’s algorithm (heavy edges, total cost 12).
Figure 3.2 draws the resulting shortest-path tree on the original network.
In a link-state routing protocol such as OSPF or IS-IS this is precisely the
computation each router performs on its own copy of the link-state database, and
the first hop of each branch — A for four of the six destinations, E for the other
two — is what is installed in the forwarding table.