Reducibility

Reducibility refers to transforming one problem into an instance of another problem. If problem A can be reduced to problem B, then solving B allows solving A. Reducibility enables proving relationships between problems.

Some examples:

  • Sorting reduces to minimum finding
  • Shortest path reduces to minimum edge
  • 3-SAT reduces to vertex cover

Java - Sorting to minimum finding:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
int[] minSort(int[] arr) {
  if (arr.length == 1) {
    return arr;
  }

  int minIndex = findMinIndex(arr);

  int[] sorted = minSort(remove(arr, minIndex)); 
  sorted = insert(sorted, 0, arr[minIndex]);

  return sorted;
} 

C++ - Shortest path to minimum edge:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
int dijkstra(Graph g, int src) {
  
  priority_queue<Edge> pq;

  // Initialize queue

  while (!pq.empty()) {
    Edge e = pq.top(); // Get min edge
    // Process edge
  }

}

Python - 3-SAT to vertex cover:

1
2
3
def reduction(formula):
  graph = constructGraph(formula) 
  return minVertexCover(graph)

Reducibility enables transferring of solutions and complexity results between problems. Useful technique for proofs.

Reducibility is a concept in computational theory that provides a formal way to show that one problem is “at least as hard as” another. In essence, if you can solve problem B quickly, then you can also solve problem A quickly. The most common form of reduction is polynomial-time reduction, often denoted as ( A \leq_p B ).

In simple terms, if you can reduce problem A to problem B, then any solution to B can be used to solve A.

Example Code in Java

Here’s an example to show how you could reduce the problem of calculating the square of a number to the problem of multiplication.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public class ReducibilityExample {
    public static int square(int x) {
        return x * x;
    }

    public static void main(String[] args) {
        int num = 5;
        int result = square(num);
        System.out.println("Square of " + num + " is " + result);
    }
}

Example Code in C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <iostream>

int square(int x) {
    return x * x;
}

int main() {
    int num = 5;
    int result = square(num);
    std::cout << "Square of " << num << " is " << result << std::endl;
    return 0;
}

Example Code in Python

1
2
3
4
5
6
def square(x):
    return x * x

num = 5
result = square(num)
print(f"Square of {num} is {result}")

These examples trivially reduce the problem of squaring a number to multiplication, showing that if you have a fast method for multiplication, you can also square a number quickly.