Algorithms

Browse the TSP solvers implemented in teeline: exact algorithms, constructive heuristics, local search and metaheuristics — each with docs and, where available, an interactive explainer.

Exact

Guarantee the mathematically optimal tour at exponential cost. Use for small instances (roughly ≤ 30 cities) or as ground truth to benchmark heuristics.

NameComplexityInteractive explainer
Bellman-Held-KarpO(2ⁿ · n²) time, O(2ⁿ · n) space▶ interactive
Branch & BoundExponential worst-case; effective pruning often makes it practical for small instances▶ interactive

Constructive

Build a tour from scratch in a single pass — greedy, spanning-tree or clustering-based. Fast and deterministic, they produce a good first tour for local search to polish.

NameComplexityInteractive explainer
Nearest NeighborO(n log n) with KD-tree▶ interactive
FourierO(K_max · epochs · (n + M) log M) per run▶ interactive
ChristofidesO(n²)▶ interactive
Greedy EdgeO(n² log n) edge sort + O(n² α(n)) scan▶ interactive
SavingsO(n² log n) edge sort + O(n² α(n)) scan▶ interactive
Kohonen SOMO(epochs · N · n) per run▶ interactive

Local search

Start from a tour and keep applying small changes — swaps, relocations, reversals — until no improvement remains. Simple, fast, and the building block of most practical solvers.

NameComplexityInteractive explainer
2-optO(n²) / pass▶ interactive
3-optO(n³) / pass▶ interactive
Or-optO(n²) / pass▶ interactive
Stochastic Hill ClimbingO(epochs · n)▶ interactive
Lin-KernighanO(epochs · n²)▶ interactive

Metaheuristic

Escape local optima with higher-level strategies — populations, simulated annealing, ant colonies, evolutionary pressure — trading more computation for tours that are usually far better than a single local search.

NameComplexityInteractive explainer
Simulated AnnealingO(epochs · n)▶ interactive
Tabu SearchO(epochs · n)▶ interactive
Genetic AlgorithmO(epochs · pop · n)▶ interactive
Particle SwarmO(epochs · swarm · n)▶ interactive
Cuckoo SearchO(epochs · nests · n)▶ interactive
Flower PollinationO(epochs · pop · n)▶ interactive
Gravitational SearchO(epochs · pop²)▶ interactive
Ant Colony OptimizationO(epochs · ants · n²)▶ interactive