Computer Networks · TEE · papers

Q7A · Bellman–Ford intermediate steps

Re-exam · 4 February 2026

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 and weights are given below. Using Bellman–Ford: (i) Determine the shortest path from A to G. (ii) Compute its shortest distance. (iii) Show all intermediate steps, including edge relaxation at each iteration. (iv) Illustrate the original topology and the final shortest path with edge distances clearly marked. Directed edges: A→B=7, A→C=6, A→D=5, B→E=−2, D→C=−2, C→B=−2, C→E=1, E→G=5, D→F=3, F→G=4. [10 marks]

Answer

Given

Directed edgeWeight
A→B7
A→C6
A→D5
B→E-2
D→C-2
C→B-2
C→E1
E→G5
D→F3
F→G4

To find

The shortest route and cost, with complete passes and a negative-cycle check.

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))

Bellman–Ford permits negative edges. We use the listed order with in-place updates; do not mix this with a table that reads only the previous pass.

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

Step-by-step solution

Step 1. Initialize

7 vertices → at most 6 main passes. d[A]=0; every other distance=∞. Use the listed edge order and immediate (in-place) updates.

Step 2. Pass 1: relax every edge

EdgeOld d[target]Candidate via sourceNew d[target]Decision
A→B∞0+(7)=77Update; predecessor=A
A→C∞0+(6)=66Update; predecessor=A
A→D∞0+(5)=55Update; predecessor=A
B→E∞7+(-2)=55Update; predecessor=B
D→C65+(-2)=33Update; predecessor=D
C→B73+(-2)=11Update; predecessor=C
C→E53+(1)=44Update; predecessor=C
E→G∞4+(5)=99Update; predecessor=E
D→F∞5+(3)=88Update; predecessor=D
F→G98+(4)=129No improvement
VertexABCDEFG
End-of-pass distance0135489
Predecessor—CDACDE

Step 3. Pass 2: relax every edge

EdgeOld d[target]Candidate via sourceNew d[target]Decision
A→B10+(7)=71No improvement
A→C30+(6)=63No improvement
A→D50+(5)=55No improvement
B→E41+(-2)=-1-1Update; predecessor=B
D→C35+(-2)=33No improvement
C→B13+(-2)=11No improvement
C→E-13+(1)=4-1No improvement
E→G9-1+(5)=44Update; predecessor=E
D→F85+(3)=88No improvement
F→G48+(4)=124No improvement
VertexABCDEFG
End-of-pass distance0135-184
Predecessor—CDABDE

Step 4. Pass 3: relax every edge

EdgeOld d[target]Candidate via sourceNew d[target]Decision
A→B10+(7)=71No improvement
A→C30+(6)=63No improvement
A→D50+(5)=55No improvement
B→E-11+(-2)=-1-1No improvement
D→C35+(-2)=33No improvement
C→B13+(-2)=11No improvement
C→E-13+(1)=4-1No improvement
E→G4-1+(5)=44No improvement
D→F85+(3)=88No improvement
F→G48+(4)=124No improvement
VertexABCDEFG
End-of-pass distance0135-184
Predecessor—CDABDE

Step 5. Stop after an unchanged pass

This entire pass changed no distance. Further identical relaxation passes will not improve anything.

Step 6. Recover and total the path

Backward predecessors: G ← E ← B ← C ← D ← A. Forward route: A → D → C → B → E → G.

Cost = (5) + (-2) + (-2) + (-2) + (5) = 4. No edge can now improve its destination label.

Final answer: A → D → C → B → E → G; shortest cost=4.

Swipe across the diagram to read its labels ↔
Bellman–Ford · final route and distances
Diagram: Bellman–Ford · final route and distances. Labels: Bellman–Ford · final route and distances | Bellman–Ford · final route and distances | A | A | 0 | B | B | 1 | A->B | 7 | C | C | 3 | A->C | 6 | D | D | 5 | A->D | 5 | E | E | -1 | B->E | -2 | C->B | -2 | C->E | 1 | D->C | -2 | F | F | 8 | D->F | 3 | G | G | 4 | E->G | 5 | F->G | 4
Highlighted route A→D→C→B→E→G, cost 5−2−2−2+5=4.

Source: Re-exam · 4 February 2026, original question paper page 3. Original marks retained; solution independently authored.