2-opt swap move
:
- Given some route , we choose two non-adjacent edges in the cycle.
- Compare the weight of these two edges. with
- If the second pair of edges are smaller than the first, , we replace the two first edges to reduce our total graph weight.
- Ensure the swap does not disconnect the graph.
2-opt approximation algorithm
The 2-opt algorithm is a polynomial-time algorithm for solving TSP that is no worse than twice the global optimal solution.
Given some graph . We can use a Minimum Spanning Tree algorithm to produce tree . Then perform Preorder traversal on the nodes in order to find a Hamiltonian cycle . Using this path, we perform 2-opt swap move on while the path is not optimal.
:
- Construct MST of
- Let be the preorder traversal of .
- While is not local optimal:
- Return
[todo:gif of pdf slides running algorithm]
Proving Approximation Ratio for 2-opt
Theorem: the 2-opt algorithm has an approximation ratio of . Proof:
- Let and denote the local optimum found by 2-opt and the global optimum Hamiltonian cycle respectively. We want to show .
- Remove one edge from to create a path .
This new path is a tree and still connects all points.

- Let denote the minimum spanning tree as computed by the first step of the 2-opt. It follows that .
- The length of the preorder traversal is at most twice the length of the spanning tree.

- Every application of the 2-opt swap only goes to further reduce the length of the cycle, such that:

- Hence we can summarise this as:
Hence, we can also state that TSP is 2-approximable.
Some algorithms push this further, such as the Christofides ‘76 algorithm, which is -approx.