Bölüm 4.2 · Simülatör

Travelling Salesman Problem

← Bölüm 4.2

Ready.

Travelling Salesman Problem

Generate cities and compare a fast Nearest Neighbor heuristic with an exact Brute Force search. Distances are Euclidean distances on the drawing (in pixels).

How to use

  • Choose the number of cities (2–10) and press Generate to place them randomly.
  • Nearest Neighbor shows the candidate edges from the current city at each step, then extends the tour.
  • Brute Force enumerates every tour starting at city 0; the best tour found so far stays visible. It is limited to 9 cities.
  • Run both on the same cities: the side panel shows how far the heuristic tour is above the optimum. Cancel stops a run.

Nearest Neighbor

At each step, the current city moves to the nearest unvisited city. It is fast, but it does not guarantee the optimal tour.

Brute Force

Checks every possible tour while fixing one city as the starting point. It finds the optimum, but its factorial growth makes it practical only for small inputs.

Complexity

MethodTimeResult
Nearest NeighborO(n²)Heuristic, not always optimal
Brute ForceO(n!) — (n − 1)! toursOptimal