← Back to Lab

Traveling Salesman

Place cities on the canvas, then watch brute force or nearest-neighbor solve the route in real time.

4
cities
3
possible routes
routes checked
best distance
Add cities by clicking the canvas or using the buttons, then hit ▶ solve.
city start city trying this route best so far final best route

why does every new city make it so much harder?

citiescalculationroutes to checkscale
With 4 cities, you have 3 × 2 × 1 = 3 routes.
Add one more city and there are 4 places to slot it into the route — so the total multiplies by 4.
That's factorial growth: each new city multiplies the problem, not adds to it.