← Back to Learn

Travelling Salesman (TSP)

Find the shortest tour visiting all cities. Watch nearest-neighbor build a tour, then 2-opt improve it by reversing segments.

ABCDEFGHunvisitedcurrentin tour2-optfinal
0/11
speed
8
cities
0
in tour
distance
init
phase
cities 8
seed ⓘ 42
setup
8 cities to visit. Build tour with nearest-neighbor, then improve with 2-opt.
complexity
NN: O(n²) 2-opt: O(n²) Exact: O(n!)

© 2026 Dantzig. Optimisation made accessible.

Powered by HiGHS