Quiz: Dijkstra and live-wire

Short questions to test your understanding. Try each on paper first, then open the answer. Pixels are nodes of a grid graph; a path pays the costs of the pixels (or links) it uses; Dijkstra repeatedly makes the unfinished pixel with the smallest tentative cost final.


Q1. Why can the row-by-row DP table not find the cheapest path when moves in all four directions are allowed?

The table needs an order in which every value is computed after the values it depends on. With moves in all directions, the best path to a pixel may come from a pixel below it (or to its right), which the row order computes later, and that pixel may in turn depend on the first one. No fixed order works in general.


Q2. Why is the unfinished pixel with the smallest tentative cost already final?

Where must any other path to it leave the set of final pixels, and what does that cost?

Any other path to it must leave the final pixels through some unfinished pixel, which already has a tentative cost at least as large; the rest of that path can only add cost (all costs are non-negative). So no other path can be cheaper.


Q3. After Dijkstra has run from a seed, how do you get the cheapest path to a pixel the mouse points at? Why is that fast?

Follow the stored predecessors from the pixel back to the seed (backtracking) and reverse. It takes as many steps as the path is long: no new shortest-path computation, so the live-wire can follow the mouse in real time. The expensive part, the tree, is computed once per seed.


Q4. Name the three terms of the live-wire local cost and what each one rewards.

Gradient magnitude: strong edges are cheap. Laplacian zero crossing: the centre of the edge (where the second derivative changes sign) is cheap, so the wire sits on the edge, not beside it. Gradient direction: running along the edge direction is cheap, cutting across it is expensive; this keeps the wire smooth and on one edge.


Q5. The wire cuts across the inside of a cell instead of following its faint boundary. Why, and what do you do?

The cost is a sum along the path: a long path along a weak edge can cost more than a short path across a uniform region. Place an anchor on the boundary (shorter pieces), or make the edge terms count more relative to the constant per-pixel cost.


Q6. Why does Dijkstra need non-negative weights, and why is that no problem for live-wire?

With a negative weight, a later detour could lower the cost of a pixel that was already declared final, so “smallest is final” breaks. The live-wire cost terms (gradient, zero crossing, direction, plus a small constant) are all \ge 0 by construction.


Q7. Dijkstra and watershed flooding use the same priority queue. What is the difference in what they minimise?

Dijkstra minimises the sum of the costs along a path. Watershed flooding minimises the maximum height along a path (the lowest pass between a pixel and a marker). Both process pixels from the queue in increasing order of their value.


Q8. (math) What is the running time of Dijkstra on an n \times n image with 8 neighbours and a binary heap?

N = n^2 pixels and about 8N edges; each pop and each update costs O(\log N): O(N \log N) = O(n^2 \log n).