In Chapter 6, we delved into the realm of complexity theory, classifying problems based on the computational resources required to solve them. We identified NP-hard problems as those that are at least as difficult as any problem in NP, and NP-complete problems as the hardest problems in NP. Assuming the widely believed conjecture that , these problems cannot be solved by any polynomial-time algorithm.

This presents a significant challenge: many NP-hard problems, such as the Traveling Salesperson Problem (TSP), the Knapsack Problem, and various scheduling and routing problems, are of immense practical importance. If we cannot solve them efficiently in the worst case, what can we do in practice? This is where the trade-off between finding an absolutely optimal solution and finding a sufficiently good solution efficiently becomes critical.

This chapter explores various algorithmic strategies designed to tackle NP-hard problems. The core idea is to transition from computationally infeasible to manageable complexity by weakening the requirements for the solution. This might involve:

  1. Restricting the Problem Instances: Focusing on subclasses of inputs that are efficiently solvable, or on “typical” instances that are easier than the worst case.
  2. Accepting Superpolynomial Algorithms: Designing algorithms that are exponential, but with a base small enough to be practical for realistic input sizes (e.g., instead of ).
  3. Weakening Solution Quality: Instead of an optimal solution, accepting a “good enough” solution (approximation algorithms).
  4. Accepting Probabilistic Guarantees: Using randomization to achieve efficiency, with a small, controlled probability of error (randomized algorithms, covered in Chapter 8).

We will explore these concepts, demonstrating how clever algorithmic design can yield practical solutions even for theoretically “hard” problems.

7.1 Aims

By the end of this chapter, you will be able to:

  • Understand Pseudopolynomial Algorithms: Recognize a class of algorithms that are efficient for number problems with small numerical values, and understand the concept of strongly NP-hard problems.
  • Design Approximation Algorithms: Develop and analyze algorithms that find near-optimal solutions for optimization problems with provable quality guarantees, such as for Vertex Cover and Metric TSP.
  • Apply Local Search Techniques: Understand the principles of local search, how neighborhoods are defined, and how it can be used to find local optima for problems like MAX-CUT.
  • Grasp Simulated Annealing: Learn about a metaheuristic that extends local search to escape local optima and find better solutions, inspired by a physical process.

7.2 Pseudopolynomial Algorithms

Some NP-hard problems, particularly those involving numbers, can be solved by algorithms whose running time is polynomial in the numerical value of the input numbers, but exponential with respect to the length of their binary representation. Such algorithms are called pseudopolynomial.

We consider number problems, where inputs can be interpreted as sequences of numbers. For an input , where are binary representations of numbers, let .

Definition 7.1 (Pseudopolynomial Algorithm)

Let be a number problem and an algorithm that solves . is a pseudopolynomial algorithm for if there exists a bivariate polynomial such that for all problem instances of .

If is bounded by a polynomial in (e.g., if the numbers in the input are small), then a pseudopolynomial algorithm runs in polynomial time with respect to the input length. This means that for “light” problem instances (where numbers are small), these algorithms are efficient.

The Knapsack Problem

The Knapsack Problem is a classic NP-hard optimization problem:

  • Input: objects, each with a weight and a benefit , and a knapsack capacity . All are positive integers.
  • Goal: Select a subset of objects such that their total weight does not exceed , and their total benefit is maximized.

We can design a pseudopolynomial algorithm for the Knapsack Problem using dynamic programming. The algorithm DPR (Dynamic Programming for Knapsack) computes, for each object and each possible total benefit , the minimum weight required to achieve benefit using a subset of the first objects.

Theorem 7.2

For every instance of the Knapsack Problem, , making DPR a pseudopolynomial algorithm.

Strongly NP-Hard Problems

Some NP-hard problems are so difficult that they don’t even admit pseudopolynomial algorithms (unless P=NP). These are called strongly NP-hard.

Definition 7.3 (Strongly NP-Hard)

A number problem is strongly NP-hard if there exists a polynomial such that the problem restricted to instances where is NP-hard.

Theorem 7.3

If is a strongly NP-hard number problem, then (assuming ) there exists no pseudopolynomial algorithm for .

This concept helps classify NP-hard problems further. For example, the Traveling Salesperson Problem (TSP) is strongly NP-hard, implying that even if all edge weights are small, it remains NP-hard and thus does not admit a pseudopolynomial algorithm (unless P=NP).


7.3 Approximation Algorithms

For many NP-hard optimization problems, finding an optimal solution is intractable. However, a solution that is “good enough” might be found efficiently. Approximation algorithms aim to find such near-optimal solutions with provable guarantees on their quality.

Definition 7.4 (Approximation Quality)

Let be an optimization problem and an algorithm for . For an instance , let be the cost of the solution found by , and be the cost of an optimal solution. The approximation quality of on is: For a positive number , is a -approximation algorithm for if for all instances . The definition ensures that , with values closer to 1 indicating better approximation.

Minimal Vertex Cover (MIN-VC)

The Vertex Cover problem is to find a minimum set of vertices in a graph such that every edge is incident to at least one vertex in the set.

Theorem 7.4

The algorithm VCA is a polynomial-time 2-approximation algorithm for MIN-VC.

Traveling Salesperson Problem (TSP)

For the general TSP, it can be proven that (assuming ) no polynomial -approximation algorithm exists for any constant . This means TSP is “too hard” for approximation in the general case.

However, for the Metric TSP (-TSP), where edge costs satisfy the triangle inequality ( for all vertices ), approximation algorithms exist.

Theorem 7.5

The algorithm SB is a polynomial-time 2-approximation algorithm for -TSP.


Local search is a general algorithmic paradigm for optimization problems. It starts with an initial feasible solution and iteratively tries to improve it by making small, local changes. The process continues until no further improvement can be made within the defined “neighborhood” of the current solution.

Definition 7.5 (Neighborhood)

For an optimization problem and an instance , a neighborhood defines, for each feasible solution , a set of “neighboring” solutions . A solution is a neighbor of . A neighborhood function typically satisfies:

  • Reflexivity: (a solution is its own neighbor, or a variant where it’s excluded if an improvement is found).
  • Symmetry: If , then .
  • Reachability: For any two solutions , there exists a path of neighbors connecting them.

An admissible solution is a local optimum with respect to if no neighbor in is better than .

Example: MAX-CUT

The MAX-CUT problem is to partition the vertices of a graph into two sets such that the number of edges between the sets is maximized.

A simple neighborhood for MAX-CUT: for a given partition , a neighbor is any partition obtained by moving a single vertex from one set to the other.

Theorem 7.6

LS-CUT is a polynomial-time 2-approximation algorithm for MAX-CUT.

A major drawback of simple local search is that it can get stuck in a local optimum that is far from the global optimum.


7.5 Simulated Annealing

Simulated Annealing (SA) is a metaheuristic inspired by the physical process of annealing metals, designed to overcome the limitation of local search by allowing the search to “jump out” of local optima.

In metallurgy, annealing involves heating a metal to a high temperature and then slowly cooling it. At high temperatures, particles have enough energy to move freely, exploring many configurations. As the temperature slowly decreases, particles settle into a low-energy, stable (optimal) configuration.

Simulated Annealing applies this idea to optimization:

  • System states correspond to admissible solutions.
  • Energy of a state corresponds to the cost of a solution.
  • Optimal state corresponds to the optimal solution.
  • Temperature is a control parameter that decreases over time.

The key feature of SA is the probabilistic acceptance of worse solutions. This probability decreases as increases (stronger deterioration is less likely) and as decreases (less likely to accept worse solutions at lower temperatures). With a carefully chosen cooling schedule, SA can converge to a global optimum, though often without guarantees on the number of iterations. It is widely used as a robust heuristic for many hard problems.


Summary

  • Tackling Intractability: For NP-hard problems, which are theoretically intractable in the worst case (assuming ), practical solutions are sought by relaxing strict requirements for optimality or efficiency.
  • Pseudopolynomial Algorithms: These algorithms are efficient when numerical input values are small, even if they are exponential in the input’s bit length. The Knapsack Problem is a prime example. Strongly NP-hard problems, however, do not admit such algorithms (unless P=NP).
  • Approximation Algorithms: These provide polynomial-time solutions for optimization problems with a provable guarantee on how close the solution is to the optimum (e.g., a 2-approximation for MIN-VC or Metric TSP). This offers a valuable trade-off between optimality and efficiency.
  • Local Search: A heuristic approach that iteratively improves a solution by making small, local changes until a local optimum is reached. While simple and widely applicable, it can get trapped in suboptimal local optima.
  • Simulated Annealing: A metaheuristic inspired by thermodynamics that enhances local search by allowing occasional moves to worse solutions. This probabilistic mechanism helps escape local optima, enabling a more thorough exploration of the solution space and often leading to better solutions for complex problems.
  • Art of Algorithm Design: This chapter highlights that even for problems deemed “hard” by complexity theory, clever algorithmic design, often involving compromises on optimality or generality, can yield effective and practical solutions.

Previous Chapter: Chapter 6 - Complexity Theory Next Up: Chapter 8 - Randomization

Exercises

Exercise 7.1 (Knapsack Problem Simulation)

Consider the Knapsack Problem instance with weights , benefits , and capacity . Simulate the DPR algorithm to find the optimal solution.

Exercise 7.2 (Strongly NP-Hard Proof)

Consider the Weighted Vertex Cover problem: given a graph with weights for each vertex , find a vertex cover such that is minimized. Prove that this problem is strongly NP-hard.

Exercise 7.3 (2-Exchange Neighborhood for TSP)

The 2-Exchange neighborhood for TSP involves taking a Hamiltonian cycle, removing two non-adjacent edges and , and adding edges and to form a new Hamiltonian cycle. Does this neighborhood satisfy the conditions of Definition 7.5 (reflexivity, symmetry, reachability)?

Exercise 7.4 (LS-CUT Polynomial Time Proof)

Prove that LS-CUT (Algorithm 7.6) is a polynomial algorithm.