Computer Networks · TEE · mocks

Q7A · Shortest paths · full working

TEE mock B · full paper

TEE · 100 attempted marks · solutions for every choice · current syllabus 702AI0C023

TEE practice mock · Q7A. For directed edges A→B=4, A→C=5, B→C=−2, B→D=6, C→D=2, D→E=3, C→E=8, use Bellman–Ford from A to E. Show the declared edge order, each pass, final distances and path; explain the negative-cycle check. [10 mock marks]

Answer

Given

Directed edgeWeight
A→B4
A→C5
B→C-2
B→D6
C→D2
D→E3
C→E8

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 | 4 | C | C | A->C | 5 | B->C | -2 | D | D | B->D | 6 | C->D | 2 | E | E | C->E | 8 | D->E | 3
Read the labels and direction before substituting numbers.

Step-by-step solution

Step 1. Initialize

5 vertices → at most 4 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+(4)=44Update; predecessor=A
A→C∞0+(5)=55Update; predecessor=A
B→C54+(-2)=22Update; predecessor=B
B→D∞4+(6)=1010Update; predecessor=B
C→D102+(2)=44Update; predecessor=C
D→E∞4+(3)=77Update; predecessor=D
C→E72+(8)=107No improvement
VertexABCDE
End-of-pass distance04247
Predecessor—ABCD

Step 3. Pass 2: relax every edge

EdgeOld d[target]Candidate via sourceNew d[target]Decision
A→B40+(4)=44No improvement
A→C20+(5)=52No improvement
B→C24+(-2)=22No improvement
B→D44+(6)=104No improvement
C→D42+(2)=44No improvement
D→E74+(3)=77No improvement
C→E72+(8)=107No improvement
VertexABCDE
End-of-pass distance04247
Predecessor—ABCD

Step 4. Stop after an unchanged pass

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

Step 5. Recover and total the path

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

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

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

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 | 4 | A->B | 4 | C | C | 2 | A->C | 5 | B->C | -2 | D | D | 4 | B->D | 6 | C->D | 2 | E | E | 7 | C->E | 8 | D->E | 3
Highlighted final shortest path, with source-to-vertex distance labels.