Computer Networks · TEE · papers

Q7A · Dijkstra with all intermediate steps

Final · 5 December 2025

TEE · Actual TEE paper · all questions · current syllabus 702AI0C023

Actual PYQ · Q7A. Consider a network topology consisting of nodes A, B, C, D, E, F, and G. The directed edges between these nodes and their corresponding positive weights are given in the table below. Using Dijkstra’s Algorithm: (i) Determine the shortest path from source A to destination G. (ii) Compute the shortest distance. (iii) Show all intermediate steps, including initialization and selection of the minimum-distance node for each iteration. (iv) Illustrate the original topology and final shortest path with edge distances. Directed edges: A→B=4, A→C=2, B→C=5, B→D=10, C→D=3, C→E=4, D→E=1, D→F=2, E→F=3, F→G=5. [10 marks]

Answer

Given

EdgeCost
A→B4
A→C2
B→C5
B→D10
C→D3
C→E4
D→E1
D→F2
E→F3
F→G5

Source=A; target=G. Edges are directed; do not add reverse edges.

To find

The path A to G, its total cost and intermediate work.

Formula and why

d[v]\leftarrow\min(d[v],d[u]+w(u,v))LaTeX: d[v]\leftarrow\min(d[v],d[u]+w(u,v))

Use Dijkstra because all weights are nonnegative. Select the smallest unsettled total distance, not the cheapest isolated edge.

Swipe across the diagram to read its labels ↔
Dijkstra · given directed graph
Diagram: Dijkstra · given directed graph. Labels: Dijkstra · given directed graph | Dijkstra · given directed graph | A | A | B | B | A->B | 4 | C | C | A->C | 2 | B->C | 5 | D | D | B->D | 10 | C->D | 3 | E | E | C->E | 4 | D->E | 1 | F | F | D->F | 2 | E->F | 3 | G | G | F->G | 5
Read the labels and direction before substituting numbers.

Step-by-step solution

Step 1. Initialize

d[A]=0; every other distance=∞. No predecessors are known.

VertexDistance from APredecessorState
A0—Tentative
B∞—Tentative
C∞—Tentative
D∞—Tentative
E∞—Tentative
F∞—Tentative
G∞—Tentative

Step 2. Settle A at distance 0

Unsettled candidates before selection: A=0, B=∞, C=∞, D=∞, E=∞, F=∞, G=∞. Select the minimum; ties use alphabetical order.

EdgeOld distanceCandidateDecision
A→B∞0+(4)=4Improve to 4; predecessor=A
A→C∞0+(2)=2Improve to 2; predecessor=A
VertexDistance from APredecessorState
A0—Settled
B4ATentative
C2ATentative
D∞—Tentative
E∞—Tentative
F∞—Tentative
G∞—Tentative

Step 3. Settle C at distance 2

Unsettled candidates before selection: B=4, C=2, D=∞, E=∞, F=∞, G=∞. Select the minimum; ties use alphabetical order.

EdgeOld distanceCandidateDecision
C→D∞2+(3)=5Improve to 5; predecessor=C
C→E∞2+(4)=6Improve to 6; predecessor=C
VertexDistance from APredecessorState
A0—Settled
B4ATentative
C2ASettled
D5CTentative
E6CTentative
F∞—Tentative
G∞—Tentative

Step 4. Settle B at distance 4

Unsettled candidates before selection: B=4, D=5, E=6, F=∞, G=∞. Select the minimum; ties use alphabetical order.

EdgeOld distanceCandidateDecision
B→C24+(5)=9Already settled; retain
B→D54+(10)=14Retain 5
VertexDistance from APredecessorState
A0—Settled
B4ASettled
C2ASettled
D5CTentative
E6CTentative
F∞—Tentative
G∞—Tentative

Step 5. Settle D at distance 5

Unsettled candidates before selection: D=5, E=6, F=∞, G=∞. Select the minimum; ties use alphabetical order.

EdgeOld distanceCandidateDecision
D→E65+(1)=6Retain 6 (equal cost)
D→F∞5+(2)=7Improve to 7; predecessor=D
VertexDistance from APredecessorState
A0—Settled
B4ASettled
C2ASettled
D5CSettled
E6CTentative
F7DTentative
G∞—Tentative

Step 6. Settle E at distance 6

Unsettled candidates before selection: E=6, F=7, G=∞. Select the minimum; ties use alphabetical order.

EdgeOld distanceCandidateDecision
E→F76+(3)=9Retain 7
VertexDistance from APredecessorState
A0—Settled
B4ASettled
C2ASettled
D5CSettled
E6CSettled
F7DTentative
G∞—Tentative

Step 7. Settle F at distance 7

Unsettled candidates before selection: F=7, G=∞. Select the minimum; ties use alphabetical order.

EdgeOld distanceCandidateDecision
F→G∞7+(5)=12Improve to 12; predecessor=F
VertexDistance from APredecessorState
A0—Settled
B4ASettled
C2ASettled
D5CSettled
E6CSettled
F7DSettled
G12FTentative

Step 8. Settle G at distance 12

Unsettled candidates before selection: G=12. Select the minimum; ties use alphabetical order.

No outgoing edges to relax.

VertexDistance from APredecessorState
A0—Settled
B4ASettled
C2ASettled
D5CSettled
E6CSettled
F7DSettled
G12FSettled

Step 9. Recover the path

Trace backwards: G ← F ← D ← C ← A. Reverse it: A → C → D → F → G.

Edge sum: 2 + 3 + 2 + 5 = 12.

Final answer: A → C → D → F → G; cost=12.

Swipe across the diagram to read its labels ↔
Dijkstra · final route and distances
Diagram: Dijkstra · final route and distances. Labels: Dijkstra · final route and distances | Dijkstra · final route and distances | A | A | 0 | B | B | 4 | A->B | 4 | C | C | 2 | A->C | 2 | B->C | 5 | D | D | 5 | B->D | 10 | C->D | 3 | E | E | 6 | C->E | 4 | D->E | 1 | F | F | 7 | D->F | 2 | E->F | 3 | G | G | 12 | F->G | 5
Highlighted final route: A→C→D→F→G; total cost 12.

Source: Final · 5 December 2025, original question paper page 3. Original marks retained; solution independently authored.