Skip to the workspace
Pebellslearn by building
Hard Problems & Adversarial Search  ›  Lesson

Approximation & Heuristics

Approximation & Heuristics 32 minDouble the MST and shortcut repeats: a tour that's never more than twice the best possible, with a proof instead of a hope

dsa / Approximation & Heuristics

Explore each scene at your own pace.

01 · Why the MST is a lower bound at all

Why the MST is a lower bound at all

Approximation & Heuristics

Definition
An approximation algorithm returns a solution to a hard optimisation problem in polynomial time with a proven bound on how far it can be from the best; for tours, shortcutting a walk around a minimum spanning tree is never more than twice the optimum.
In plain words
When the perfect route is too slow to find, you settle for a good one with a guarantee. Walk around the cheapest connecting network, skip any city you have already seen, and you know the result is at most double the best possible.

In short: brute-force TSP doesn't scale, and no algorithm known today solves it exactly in polynomial time. But Meridian still has to ship a route. The fix is a proven approximation: grow a minimum spanning tree (section 17's relay backbone), walk it so that every edge is visited twice — once in, once out — then shortcut past any city you've already seen. The result is never more than twice the length of the best possible tour, and that's not a hope, it's provable, because the MST weight is itself a lower bound on any tour at all. A different heuristic, nearest-neighbour, has no such proof behind it — it's here for contrast, not as a replacement.

Three panels: an MST star, the same tree with every edge walked out-and-back shown as dashed loops, and the final shortcut tour drawn as a solid triangle, captioned "every edge walked twice costs 2x the MST weight, and skipping repeats never makes a metric tour longer"

Why the MST is a lower bound at all

Remove any one edge from the optimal tour and what's left is a path touching every city — which is itself a spanning tree, just not necessarily the cheapest one. So:

optimal tour cost ≥ (optimal tour minus one edge) ≥ MST weight

That one inequality is the entire foundation. Nothing about approximating TSP works without first having something to measure against, and the MST is cheap to compute exactly (section 17) even though the tour itself isn't.

watch it move · graph

The relay backbone's MST, weight 10. Walking every edge out and back would cost 20 — but the shortcut tour never needs to.

The MST here keeps central-north (3), central-harbor (4) and harbor-mill (3): weight 10. This is the lower bound every tour on these four depots has to beat. 4 nodes, 6 edges, undirected.

1 / 2
Scene 1 of 6
Project context and further resources
You're building a piece ofMeridian — the bid desk
This piece — approximate_bid_route(): Builds a tour from the relay backbone's minimum spanning tree that is never more than twice the length of the best possible route.
Scenario Meridian's bid desk can't afford to brute-force the optimal route through every tender -- but it can afford to build the relay backbone's minimum spanning tree and walk it, and prove in advance that the result is never worse than double the best possible answer.
approximate_bid_route.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
approximate_bid_route(cities, edges) → dictA tour built from the MST's preorder walk, its cost, the MST weight it's measured against, and the ratio between them.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.