Exercises — Link state routing — OSPF, Dijkstra
We reuse one small network for several problems. Look at it first — every symbol is defined on the picture:

L1 — Recognition
Problem 1.1
Which of these does a router flood to the whole network in link state routing: (a) its full routing table, (b) its best distance to every destination, (c) its own Link State Packet (LSP), (d) the shortest path to the source?
Recall Solution
(c) its own LSP = {its ID, list of (neighbor, cost)}. It floods only its local roads, not computed distances (that would be distance-vector) and not full routing tables. Each router then assembles all LSPs into the same map.
Problem 1.2
OSPF runs directly over IP as protocol number ___ , and its name expands to ___ .
Recall Solution
Protocol number 89; Open Shortest Path First. It is an intra-domain IGP (interior gateway protocol), see OSPF Areas for how it scales.
Problem 1.3
Match each phrase to LS (link state) or DV (distance vector): (i) "share the full map, compute alone", (ii) "share computed distances, trust neighbors", (iii) "vulnerable to count-to-infinity".
Recall Solution
(i) LS, (ii) DV, (iii) DV. See Distance Vector Routing and Bellman–Ford Algorithm for why DV suffers count-to-infinity while LS does not.
L2 — Application
Problem 2.1
Using the network in the figure (source = A), run Dijkstra and fill the tentative-distance table for all of B, C, D, E. Give the final for each.
Edges: A–B = 2, A–C = 5, B–C = 1, B–D = 7, C–D = 3, C–E = 6, D–E = 1.
Recall Solution
We repeatedly pick the smallest unfinalized , lock it, relax its edges. Non-negative weights make this greedy step safe.
| Step | Finalized | d[B] | d[C] | d[D] | d[E] |
|---|---|---|---|---|---|
| init (A, d=0) | {A} | 2 | 5 | ∞ | ∞ |
| pick B (min=2) | {A,B} | 2 | 3 (2+1) | 9 (2+7) | ∞ |
| pick C (min=3) | {A,B,C} | 2 | 3 | 6 (3+3) | 9 (3+6) |
| pick D (min=6) | {A,B,C,D} | 2 | 3 | 6 | 7 (6+1) |
| pick E (min=7) | all | 2 | 3 | 6 | 7 |
- drops because A→B→C () beats direct A→C ().
- drops because relaxing D→E gives , beating C→E's .
- Final: .

Problem 2.2
For the same run, state the next hop router A stores in its forwarding table to reach each of C, D, E.
Recall Solution
Trace each shortest path back to its first hop out of A:
- To C: path A→B→C ⇒ next hop B.
- To D: path A→B→C→D ⇒ next hop B.
- To E: path A→B→C→D→E ⇒ next hop B.
A stores only destination → next-hop, never the whole path (see Routing Table vs Forwarding Table). Every destination here begins with the hop to B.
L3 — Analysis
Problem 3.1
In a run with source A, node X gets finalized with . Later, relaxing some edge produces a candidate . What went wrong, and what does it prove about the graph?
Recall Solution
Nothing can lower a finalized distance in a valid Dijkstra run — unless a negative edge exists. The candidate means a path reached X more cheaply after X was locked, which is only possible if some edge on that path had negative weight. Conclusion: the graph violates Dijkstra's non-negativity assumption; you must use Bellman–Ford Algorithm instead.
Problem 3.2
Give a tiny 3-node graph with one negative edge where Dijkstra (from source S) returns a wrong shortest distance. Show the correct answer.
Recall Solution
Let edges be: S→A = 2, S→B = 5, A→B = −4.
- Dijkstra from S: . It finalizes A first (min = 2), then relaxes A→B: . Here B is corrected to −2, but consider instead B finalized before A's edge is relaxed in a variant where B is reached first cheaply. The clean failure: with S→B = 1, S→A = 2, A→B = −4: Dijkstra pops B first (min = 1), locks , then can never apply A→B = −4 which would give .
- Correct shortest ; Dijkstra returns . Wrong, because B was locked before the cheaper negative path appeared.
This is exactly why the greedy invariant needs .
L4 — Synthesis
Problem 4.1
A link B–C fails (cost 1 removed) in the network of Problem 2.1. (a) Describe the LSP/flooding events. (b) Recompute A's shortest distances to all nodes.
Recall Solution
(a) B and C each detect the dead link (missed HELLOs), each builds a new LSP with a higher sequence number, and floods it. Every router replaces its old LSP-from-B and LSP-from-C with the newer ones, rebuilds an identical map, and reruns Dijkstra. No count-to-infinity — everyone recomputes on the same fresh map.
(b) New edges: A–B=2, A–C=5, B–D=7, C–D=3, C–E=6, D–E=1 (B–C gone).
| Step | Finalized | d[B] | d[C] | d[D] | d[E] |
|---|---|---|---|---|---|
| init (A) | {A} | 2 | 5 | ∞ | ∞ |
| pick B (2) | {A,B} | 2 | 5 | 9 (2+7) | ∞ |
| pick C (5) | {A,B,C} | 2 | 5 | 8 (5+3) | 11 (5+6) |
| pick D (8) | {A,B,C,D} | 2 | 5 | 8 | 9 (8+1) |
| pick E (9) | all | 2 | 5 | 8 | 9 |
Final: . Losing the cheap B–C shortcut raised C from 3→5 and cascaded downstream.
Problem 4.2
OSPF splits large networks into areas so that not everyone floods to everyone. In one line, what is the trade-off versus running one flat Dijkstra over the whole Internet?
Recall Solution
Trade-off: areas cut flooding scope and LSP-database size (better scaling), but a router no longer has the full map — it sees summarized routes between areas, so paths can be slightly sub-optimal. See OSPF Areas; across domains you switch to BGP entirely.
L5 — Mastery
Problem 5.1
Prove the greedy invariant: when Dijkstra pops the unfinalized node with smallest , that is already the true shortest distance (assume all ).
Recall Solution
Let be the finalized set, and suppose is the popped minimum. Assume for contradiction a shorter true path to exists with length .
- starts inside (at the source) and ends at , so it must cross the boundary: let be the first node on not in , reached from .
- When was finalized, its edge to was relaxed, so .
- Since all remaining edges of from to are , the whole path satisfies .
- But was chosen as the minimum, so . Chaining: — a contradiction.
Hence no shorter path exists; is final. The non-negativity was used exactly at "remaining edges ."
Problem 5.2
Design a graph on 4 nodes (all ) where the shortest path from A to D has more hops than the direct A–D edge yet lower cost. State both.
Recall Solution
Edges: A–D = 10 (direct, 1 hop), A–B = 3, B–C = 3, C–D = 3.
- Direct: cost 10, 1 hop.
- Detour A→B→C→D: cost 9, 3 hops.
- : the longer-hop path wins. Dijkstra finalizes D at (via C), and A's forwarding next hop to D is B. This shows hop count ≠ cost; OSPF optimizes cost, not hops.
Active recall
Recall Quick self-check (hide answers)
- After a link fails, how many flooding passes does LS need to reconverge, roughly? ::: One reflood of the new LSPs, then each router reruns Dijkstra once.
- Can a finalized Dijkstra distance ever decrease? ::: No — unless a negative edge exists (then use Bellman–Ford).
- Does the cheapest path always have the fewest hops? ::: No; cost and hop-count are independent (Problem 5.2).
- What exactly does non-negativity guarantee in the proof? ::: The tail of any alternative path can't be negative, so it can't undercut the popped minimum.
Connections
- Dijkstra's Algorithm — the engine every problem here drives
- Bellman–Ford Algorithm — the fix when weights go negative (L3)
- Distance Vector Routing — the count-to-infinity contrast (L4)
- Flooding — how LSPs reach everyone (L4)
- OSPF Areas — scaling flooding (L4.2)
- BGP — inter-domain, where LS stops
- Routing Table vs Forwarding Table — destination → next-hop (L2.2)