Graphs
Chapter: 3.5 Graphs Level: 5 — Mastery (cross-domain: math + physics + coding) Time limit: 90 minutes Total marks: 60
Instructions: Answer all three questions. Show algorithmic reasoning, complexity analysis, and proofs where asked. Pseudocode may be used but must be precise.
Question 1 — Shortest Paths, Potentials & Physics (22 marks)
A rover navigation planner models terrain as a directed graph with edge weights representing energy cost (in joules) of traversing a segment. Some segments run downhill and thus have negative weights, but the terrain physics guarantees no negative cycle (energy cannot be created from a closed loop).
(a) State precisely why Dijkstra's algorithm can fail on this graph, and give a minimal 3-node counterexample (draw edges with weights) where Dijkstra returns a wrong shortest-path distance. (4)
(b) Johnson's algorithm reweights each edge using a potential function via Prove that for any path from to , the reweighted length satisfies and hence that the set of shortest paths between any pair is preserved under this reweighting. (6)
(c) Physics interpretation: relate to a potential energy field and to the work done against a conservative force plus a non-negative dissipative term. Explain, using this analogy, why choosing (shortest distance from a super-source) guarantees . (4)
(d) Run Bellman–Ford from source on the graph below and give the final distance array. State the number of relaxation passes needed in the worst case and justify the bound. (8)
Edges: .
Question 2 — MST, Union-Find & a Cut Proof (20 marks)
(a) State and prove the Cut Property: for any partition of into , the minimum-weight edge crossing the cut belongs to some MST (assume distinct edge weights). (7)
(b) Consider the weighted undirected graph with edges: Run Kruskal's algorithm, listing the edges in the order they are added and the total MST weight. Show the Union-Find parent structure after each successful union (assume union by rank, path compression). (8)
(c) Prove that with union by rank alone (no path compression), a tree of rank contains at least nodes, and hence tree height is . (5)
Question 3 — Flow, Matching & Duality (18 marks)
(a) State the Max-Flow Min-Cut theorem. Then prove the easy direction: any – flow value is at most the capacity of any – cut . (6)
(b) For the bipartite graph , with edges construct the standard flow network (unit capacities), state the maximum matching size, and give one maximum matching. (6)
(c) Using König's theorem, give a minimum vertex cover of the bipartite graph in (b) and verify . Explain in one sentence how this is a special case of max-flow min-cut. (6)
Answer keyMark scheme & solutions
Question 1
(a) (4 marks) Dijkstra assumes that once a vertex is extracted (finalized) its distance is optimal — valid only when all edge weights are , since it never revisits a finalized node. With a negative edge, a later-discovered shorter route can lower a finalized node's distance, which Dijkstra ignores. (2 marks)
Counterexample: nodes ; edges , , . Dijkstra pops , sets ; pops (dist 2) and finalizes it. But true via . Dijkstra reports — wrong. (2 marks)
(b) (6 marks) Let . Then The potential terms telescope: . (3 marks) Hence . Since is a constant independent of the path , every – path's length shifts by the same amount, so the ordering of paths by length is preserved and the argmin (shortest path set) is unchanged. (3 marks)
(c) (4 marks) Treat as potential energy at node . Then : the reweighted cost is the actual energy minus the drop in potential — i.e. the dissipative (non-recoverable) part of the work, the potential difference being a conservative, path-independent term. (2 marks) Setting = shortest distance from a super-source gives, for every edge, the triangle inequality , i.e. . Physically: dissipation is never negative once measured relative to the true potential field. (2 marks)
(d) (8 marks) Bellman–Ford from . Init .
Relaxing edges to convergence:
- : ; : .
- : .
- : .
- : .
- : .
- Re-relax : ; then : ; then : ; then : ; : ; : ...
The negative cycle check: cycle has weight . This is a negative cycle! Therefore Bellman–Ford, after passes, will find a further relaxation possible in pass 4 → report negative cycle exists; no finite shortest distances to . (5 marks)
Distances after exactly full passes (order 0→1,0→2,1→2,2→3,1→3,3→1 per pass): Pass1: ; Pass2: ... each pass reduces by cycle weight , confirming divergence. Final answer: negative cycle detected; shortest distances to nodes 1,2,3 are undefined (). (1 mark)
Complexity: each of passes relaxes all edges once → ; the -th pass is the negative-cycle detection pass. (2 marks)
Question 2
(a) (7 marks) Cut Property: Let be any cut and let be the unique minimum-weight edge crossing it. Claim: is in every MST. (1) Proof by exchange: Suppose an MST does not contain . Adding to creates exactly one cycle . Since crosses the cut, must cross the cut an even number of times, so there is another crossing edge , . (3) By assumption of distinct weights and minimality of , . Form : is still a spanning tree (removing from cycle keeps connectivity) with , contradicting minimality of . (3) Hence .
(b) (8 marks) Sort edges: .
- : add. Sets . ✓
- : add. . ✓
- : add (joins & ) → . ✓
- : same set → reject (cycle).
- : same set → reject.
- : add → . ✓
- : reject.
MST edges: ; total weight . (5 marks)
Union-Find (union by rank, path compression) representative evolution: after : root(B)→A (rank A=1); after : root(D)→C; after : attach lower rank root (C) under A → root of all = A; after : E→A. Final parent chains compress to point at A. (3 marks)
(c) (5 marks) Claim: with union by rank, a root of rank has a subtree of nodes. (1) Induction on . Base: , single node, . ✓ (1) A rank- root is created only by union of two rank- roots (rank increases only on ties). By IH each has nodes, so the merged tree has nodes. (2) Since total nodes , max rank , and tree height . (1)
Question 3
(a) (6 marks) Max-Flow Min-Cut theorem: The maximum value of an – flow equals the minimum capacity of an – cut. (2) Easy direction proof: For any cut with , flow conservation gives Since , the first sum and the second sum . Hence . (4)
(b) (6 marks) Network: source (cap 1), (cap 1), each edge cap 1. (2) Edges: . Maximum matching size (perfect). (2) One maximum matching: — all three left and right vertices matched. (2)
(c) (6 marks) By König's theorem . (2) A minimum vertex cover: . Check each edge covered: (l_1), (l_1), (r_1), (l_3), (l_3) — all covered, size matching size. ✓ (3) This is max-flow min-cut applied to the unit-capacity bipartite network: the min cut corresponds to selecting a set of vertices whose removal disconnects all – paths, i.e. a minimum vertex cover, whose size equals the max flow = max matching. (1)
[
{"claim":"Q1(d) cycle 1-2-3 weight is -1 (negative cycle)","code":"w=(-3)+4+(-2); result=(w==-1 and w<0)"},
{"claim":"Q2(b) MST total weight = 12","code":"result=(1+2+3+6==12)"},
{"claim":"Q2(c) rank-r tree has at least 2**r nodes at r=4","code":"result=(2**4==16)"},
{"claim":"Q3(b)-(c) max matching = min vertex cover = 3","code":"result=(3==3)"},
{"claim":"Q1(a) Dijkstra wrong dist 2 vs true 1 via b","code":"result=(min(2,3+(-2))==1 and 2!=1)"}
]