Mathwords logoMathwords

Approximation Algorithm — Definition, Formula & Example

An approximation algorithm is a fast method for a hard optimization problem that may not find the best answer. It does come with a proof that its answer is never worse than a fixed factor times the best possible answer.

Let Π\Pi be an optimization problem, and let OPT(I)\text{OPT}(I) be the optimal objective value on instance II. A polynomial-time algorithm AA is a ρ\rho-approximation algorithm, with ρ≥1\rho \ge 1, if for every instance II it returns a feasible solution that satisfies the bound. For a minimization problem the bound is cost(A(I))≤ρ⋅OPT(I)\text{cost}(A(I)) \le \rho \cdot \text{OPT}(I). For a maximization problem it is value(A(I))≥OPT(I)/ρ\text{value}(A(I)) \ge \text{OPT}(I)/\rho. The number ρ\rho is called the approximation ratio. Some authors use ρ≤1\rho \le 1 for maximization.

Key Formula

ALG(I)≤ρ⋅OPT(I)for every instance I\text{ALG}(I) \le \rho \cdot \text{OPT}(I) \quad \text{for every instance } I
Where:
  • II = Any input instance of the problem
  • ALG(I)\text{ALG}(I) = Cost of the solution the algorithm returns on I
  • OPT(I)\text{OPT}(I) = Cost of a best possible solution on I
  • ρ\rho = Approximation ratio, a constant at least 1 (minimization form shown)

Worked Example

Problem: Five jobs take 3, 3, 2, 2, and 2 hours. You run Graham's list scheduling on 2 identical machines: take the jobs in that order and give each one to the machine with the smaller current load. This algorithm is proven to keep the finishing time (makespan) within a factor of 2−1m2 - \tfrac{1}{m} of optimal on mm machines. Find its makespan and check it against the guarantee.
Step 1: Run the algorithm. Machine 1 gets 3, and machine 2 gets 3. The loads are tied, so machine 1 gets the first 2 (load 5). Machine 2 gets the next 2 (load 5). Machine 1 gets the last 2. The makespan is the larger final load.
max⁡(3+2+2,  3+2)=7\max(3+2+2,\; 3+2) = 7
Step 2: Bound the optimum from below. Any schedule must fit 12 hours of work on 2 machines, so some machine runs at least the average. The split {3, 3} and {2, 2, 2} reaches this bound, so the optimum is exactly 6.
OPT≥3+3+2+2+22=6,3+3=2+2+2=6\text{OPT} \ge \frac{3+3+2+2+2}{2} = 6, \qquad 3+3 = 2+2+2 = 6
Step 3: Compare the result with the guarantee. With m=2m = 2, the ratio is 2−12=322 - \tfrac12 = \tfrac32, so the guaranteed ceiling is 32⋅6=9\tfrac32 \cdot 6 = 9 hours. The algorithm's ratio on this input is well under that.
76≈1.17≤32\frac{7}{6} \approx 1.17 \le \frac{3}{2}
Answer: List scheduling finishes in 7 hours, while the optimum is 6 hours. The ratio is 7/6≈1.177/6 \approx 1.17, which is within the proven bound of 3/23/2.

Why It Matters

Many scheduling, routing, and covering problems are NP-hard, so no known algorithm solves every instance exactly in polynomial time. Approximation algorithms give provable answers anyway. Examples include a 2-approximation for vertex cover using a maximal matching, a 2-approximation for metric TSP built from a minimum spanning tree, and greedy set cover within a factor of about ln⁡n\ln n. They are a core chapter in undergraduate algorithms courses and are used in operations research and chip layout.

Common Mistakes

Mistake: Treating the ratio seen on one input, such as 7/6 above, as the algorithm's approximation ratio.
Correction: The ratio ρ\rho is a worst-case guarantee that must hold for every instance. Some inputs perform better than ρ\rho. To establish ρ\rho, you need a proof covering all inputs, usually done by comparing the output to a lower bound on OPT, as in Step 2.

Related Terms

  • Combinatorics — Field supplying the discrete optimization problems being approximated
  • Algorithm — General notion this term restricts with a proven guarantee
  • Greedy Algorithm — Strategy behind many approximation algorithms, including list scheduling
  • Minimum Vertex Cover — NP-hard problem with a classic matching-based 2-approximation
  • Kruskal's Algorithm — Builds the spanning tree used in TSP 2-approximation