Nivaar Exam Prep

22-Elec-B4 Information Technology Networks · December 2015

Question 5 of 5: Shortest-path routing

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer) · Last updated

Notes on this paper

Reference texts.

Question 5 — Shortest-path routing (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. An undirected network of seven nodes A to G and ten weighted edges, read from the figure printed with the question:

Given data — edge lengths
EdgeLengthEdgeLengthEdgeLength
A–B1C–D1E–F1
A–C2C–F2E–G1
A–D2D–F1F–G3
B–E5Source node: B

Find. The least-cost path and its total length from node B to each of A, C, D, E, F and G, obtained by a correct execution of Dijkstra's algorithm with the working shown at every iteration.

[Figure not reproduced: The network as printed with the question: seven nodes, ten undirected edges, with the length marked on each edge. See the official exam paper.]

Approach. Maintain a set $S$ of nodes whose shortest distance is already known, together with a tentative label $d(v)$ for every other node; at each iteration move the unlabelled node of smallest label into $S$ and relax its edges.

  1. Initialise. Put the source in the permanent set and label every other node with the direct edge from B if one exists, otherwise infinity: $$S=\{B\},\quad d(B)=0,\quad d(A)=1,\quad d(E)=5,\quad d(C)=d(D)=d(F)=d(G)=\infty.$$ Only A and E adjoin B, so only those two labels are finite at the start.
  2. Iteration 1 — make A permanent. The smallest tentative label is $d(A)=1$, so A joins $S$. Relaxing A's edges, the routes B → A → C and B → A → D each cost $1+2=3$, improving both labels from infinity: $$d(C)\leftarrow3,\qquad d(D)\leftarrow3,\qquad S=\{B,A\}.$$
  3. Iteration 2 — make C permanent. C and D are tied at 3; the algorithm may take either, and taking C first gives $S=\{B,A,C\}$. Relaxing C's edges, the route through C to D would cost $3+1=4$, which does not improve $d(D)=3$, while F is reached for the first time: $$d(F)\leftarrow3+2=5,\qquad d(D)\ \text{unchanged at }3.$$ This is a useful check that the tie was harmless — D keeps the label it already had.
  4. Iteration 3 — make D permanent. With $d(D)=3$ the smallest remaining, D joins $S$. Its edge to F now offers a cheaper route, so the tentative label improves: $$d(F)\leftarrow\min(5,\ 3+1)=4\quad\text{via }B\rightarrow A\rightarrow D\rightarrow F.$$
  5. Iteration 4 — make F permanent. $d(F)=4$ is now the smallest label outstanding. Relaxing F gives $$d(E)\leftarrow\min(5,\ 4+1)=5,\qquad d(G)\leftarrow4+3=7.$$ The label on E is a genuine tie: the direct edge B–E and the path B → A → D → F → E both cost 5, so the shortest-path tree is not unique. Keeping the incumbent is the standard convention.
  6. Iteration 5 — make E permanent. E enters with $d(E)=5$, and its edge of length 1 to G improves the last outstanding label: $$d(G)\leftarrow\min(7,\ 5+1)=6\quad\text{via }B\rightarrow E\rightarrow G.$$ Note that the F–G edge of length 3, which produced the earlier label of 7, ends up on no shortest path at all.
  7. Iteration 6 — make G permanent and stop. G joins $S$ with $d(G)=6$; every node is now permanent, so the algorithm terminates: $$\boxed{d(A)=1,\ d(C)=3,\ d(D)=3,\ d(F)=4,\ d(E)=5,\ d(G)=6}$$
Dijkstra iteration table — tentative labels after each step (permanent labels in bold)
StepNode made permanentPermanent set Sd(A)d(C)d(D)d(E)d(F)d(G)
0B (source){B}1∞∞5∞∞
1A (1){B,A}1335∞∞
2C (3){B,A,C}13355∞
3D (3){B,A,C,D}13354∞
4F (4){B,A,C,D,F}133547
5E (5){B,A,C,D,F,E}133546
6G (6)all133546

Tracing each predecessor back to the source recovers the routes themselves, which are what a router would actually install in its forwarding table.

[Figure not reproduced: The resulting shortest-path tree rooted at B, drawn heavy over the original network. The C-F and F-G edges carry no shortest path. See the official exam paper.]

Question 5 — shortest paths from node B
DestinationLeast costRouteNote
A1B → Adirect edge
C3B → A → C—
D3B → A → Dtied with C for the second selection
E5B → Eties with B → A → D → F → E, also 5
F4B → A → D → F—
G6B → E → Gties with B → A → D → F → E → G, also 6
Back to the paper →