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 edge | Weight |
|---|---|
| A→B | 4 |
| A→C | 5 |
| B→C | -2 |
| B→D | 6 |
| C→D | 2 |
| D→E | 3 |
| C→E | 8 |
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))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.
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
| Edge | Old d[target] | Candidate via source | New d[target] | Decision |
|---|---|---|---|---|
| A→B | ∞ | 0+(4)=4 | 4 | Update; predecessor=A |
| A→C | ∞ | 0+(5)=5 | 5 | Update; predecessor=A |
| B→C | 5 | 4+(-2)=2 | 2 | Update; predecessor=B |
| B→D | ∞ | 4+(6)=10 | 10 | Update; predecessor=B |
| C→D | 10 | 2+(2)=4 | 4 | Update; predecessor=C |
| D→E | ∞ | 4+(3)=7 | 7 | Update; predecessor=D |
| C→E | 7 | 2+(8)=10 | 7 | No improvement |
| Vertex | A | B | C | D | E |
|---|---|---|---|---|---|
| End-of-pass distance | 0 | 4 | 2 | 4 | 7 |
| Predecessor | — | A | B | C | D |
Step 3. Pass 2: relax every edge
| Edge | Old d[target] | Candidate via source | New d[target] | Decision |
|---|---|---|---|---|
| A→B | 4 | 0+(4)=4 | 4 | No improvement |
| A→C | 2 | 0+(5)=5 | 2 | No improvement |
| B→C | 2 | 4+(-2)=2 | 2 | No improvement |
| B→D | 4 | 4+(6)=10 | 4 | No improvement |
| C→D | 4 | 2+(2)=4 | 4 | No improvement |
| D→E | 7 | 4+(3)=7 | 7 | No improvement |
| C→E | 7 | 2+(8)=10 | 7 | No improvement |
| Vertex | A | B | C | D | E |
|---|---|---|---|---|---|
| End-of-pass distance | 0 | 4 | 2 | 4 | 7 |
| Predecessor | — | A | B | C | D |
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.