Computer Networks · TEE · papers

Q7(a) · Bellman-Ford directed graph

2023-11-22 · Final 2023-24 / Re-exam 2022-23

Actual paper; 100 marks attempted. Current-syllabus alignment is stated per question.

Q7(a). Consider the directed graph with costs given below. Determine the shortest path from source vertex A to every other vertex in the graph using Bellman Ford Algorithm. Illustrate step-by-step procedure and draw the shortest path table. [10 marks]

Original diagram data

FromToCost
AB4
AC3
AD6
CB-1
DC-4
BE-1
CE2
DF-2
EF3

Answer

Given

The original diagram is directed. All edge labels are reproduced below. Source = A.

Swipe across the diagram to read its labels ↔
bellman 2023 original question graph
Diagram: bellman 2023 original question graph. Labels: bellman 2023 original question graph | 4 | 3 | 6 | -1 | -4 | -1 | 2 | -2 | 3 | A | B | C | D | E | F
FromToCost
AB4
AC3
AD6
CB-1
DC-4
BE-1
CE2
DF-2
EF3

To find

Shortest distance, complete route and predecessor for every node from A.

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

Relaxation replaces a tentative route when going through u is cheaper. Bellman–Ford permits negative edge weights. This table uses synchronous passes: pass k uses distances at the end of pass k−1, so it covers paths of at most k edges.

Step 1. Initialize and relax

Pass / settled nodeStrict improvementsABCDEF
0Initial0∞∞∞∞∞
1B←A: 0+(4)=4; C←A: 0+(3)=3; D←A: 0+(6)=60436∞∞
2B←C: 3+(-1)=2; C←D: 6+(-4)=2; E←B: 4+(-1)=3; F←D: 6+(-2)=4022634
3B←C: 2+(-1)=1; E←B: 2+(-1)=1012614
4E←B: 1+(-1)=0012604
5F←E: 0+(3)=3012603

Step 2. Read predecessors backwards, then reverse

DestinationDistancePreviousRoute
A0—A
B1CA → D → C → B
C2DA → D → C
D6AA → D
E0BA → D → C → B → E
F3EA → D → C → B → E → F

Step 3. Check for a reachable negative cycle

EdgeCandidate d[u] + weightCurrent d[v]Improvement?
A → B0 + (4) = 41No
A → C0 + (3) = 32No
A → D0 + (6) = 66No
C → B2 + (-1) = 11No
D → C6 + (-4) = 22No
B → E1 + (-1) = 00No
C → E2 + (2) = 40No
D → F6 + (-2) = 43No
E → F0 + (3) = 33No

No edge improves its destination on the extra pass. Therefore no negative cycle reachable from the source is detected.