Algorithm Class Lecture 5
Algorithm Class Lecture 5
Reductions
1
Takeaway from Bipartite Matching
• We saw how to solve a problem (bi-partite
matching and others) by reducing it to another
problem (maximum flow).
• In general, we can design an algorithm to map
instances of a new problem to instances of a
known solvable problem (e.g., max-flow) to
solve this new problem!
• Mapping from one problem to another which
preserves solutions is called reduction.
2
Reduction: Basic Idea
Convert solutions to the known problem to the
solutions to the new problem
3
Reduction: Formal Definition
• Problems 𝐿, 𝐾
𝐾
Φ
𝐿 𝐾′
4
Using reduction to design algorithms
In the example of reduction to solve Bipartite Matching:
𝐿:
𝐾:
Efficiency:
1. Reduction: Φ: 𝑙 → Φ(𝑙)
2. Solve problem Φ(𝑙)
3. Convert the solution for Φ(𝑙) to a solution to 𝑙
5
Efficient Reduction
A reduction Φ: 𝐿 → 𝐾 is efficient (𝐿 ≤𝒑 𝐾) if for any
𝑙 ∈ 𝐿:
1. Φ(𝑙) is computable from 𝑙 in polynomial (|𝑙|) time.
2. Solution to 𝑙 is computable from solution of Φ(𝑙) in
polynomial (|𝑙|) time.
6
Which problem is harder?
Theorem: If 𝐿 ≤" 𝐾 and there is a polynomial time
algorithm to solve 𝐾, then there is a polynomial time
algorithm to solve 𝐿.
Proof: Given an instance of 𝑙 ∈ 𝐿
1. Compute Φ(𝑙):
2. Solve Φ(𝑙):
3. Convert solution:
Total time:
Need to show:
7
Φ 𝑙 = 𝑝𝑜𝑙𝑦 𝑙 ?
Proof:
8
Hardness Problems
• Reductions show the relationship between
problem hardness!
Question: Could you solve a problem in polynomial
time?
Easy:
Hard:
9
Types of Problems
Decision Problem: Yes/No answer
• Examples:
1.
2.
3.
Optimization Problem: What is the value of an
optimal feasible solution of a problem?
• Minimization:
• Maximization:
10
Canonical Decision Problem
Does the instance 𝑙 ∈ 𝐿 (an optimization problem) have
a feasible solution with objective value 𝑘:
11
Hardness of Canonical Decision Problems
Lemma 1: 𝐷𝐿 ≤! 𝐿
Proof: Assume 𝐿 maximization problem
𝐷𝐿(𝑙): does 𝑙 have a solution ≥ 𝑘.
Let 𝑣 ∗ 𝑙 be the maximum objective on 𝑙 by solving 𝑙.
12
Hardness of Canonical Decision Problems
Lemma 2: If 𝑣 ∗ 𝑙 = 𝑂(𝑐 # ) for any constant 𝑐, then
𝐿 ≤! 𝐷𝐿.
Proof: First we could show 𝐿 ≤ 𝐷𝐿. Suppose maximization
problem, canonical decision problem is is there a solution ≥ 𝑘.
Naïve Linear Search: Ask 𝐷𝐿(𝑙, 𝑘), if returns false, ask
𝐷𝐿 𝑙, 𝑘 + 1 until returns true
Runtime:
01 2 4 8 16
14
Reduction for Algorithm Design vs
Hardness
• Problems 𝐿, 𝐾
𝐾
Φ
𝐿 poly
𝐿′
16
Reduction for Hardness: Independent
Set (ISET)
Input: Given an undirected graph 𝐺 = 𝑉, 𝐸
A subset of vertices 𝑆 ⊆ 𝑉 is called an independent set if
no two vertices of 𝑆 are connected by an edge.
Problem: Does 𝐺 contain an independent set of size ≥ 𝑘?
𝐼𝑆𝐸𝑇 𝐺, 𝑘 returns true if 𝐺 contains an independent set
of size ≥ 𝑘, and false otherwise.
Algorithm? NO! We think that this is a hard problem.
A lot of people have tried and could not find a
poly-time solution
17
Pause to reflect
18
Example: Vertex Cover (VC)
Input: Given an undirected graph 𝐺 = 𝑉, 𝐸
A subset of vertices C ⊆ 𝑉 is called a vertex cover if 𝐶
contains at least one end point of every edge.
Formally, for all edges (𝑢, 𝑣) ∈ 𝐸, either 𝑢 ∈ 𝐶, or 𝑣 ∈ 𝐶.
Problem: 𝑉𝐶(𝐺, 𝑗) returns true if 𝐺 has a vertex cover of size
≤ 𝑗, and false otherwise
Example:
19
How hard is Vertex Cover?
Claim: 𝐼𝑆𝐸𝑇 ≤" 𝑉𝐶
Side Note:
DO NOT:
Proof: Show that 𝐺 = (𝑉, 𝐸) has an independent set of 𝑘
if and only if the same graph (not always!) has a vertex
cover of size 𝑉 − 𝑘.
Map:
𝐼𝑆𝐸𝑇 𝐺, 𝑘 → 𝑉𝐶( )
20
Proof of reduction: Direction 1
Claim 1: 𝐼𝑆𝐸𝑇 of size 𝑘 à 𝑉𝐶 of size 𝑉 − 𝑘
Proof: Assume 𝐺 has an ISET of size 𝑘: 𝑆, consider 𝐶 =
𝑉 − 𝑆, 𝐶 = 𝑉 − 𝑘
• Claim: 𝐶 is a vertex cover
21
Proof of reduction: Direction 2
Claim 2: 𝑉𝐶 of size 𝑉 − 𝑘 à 𝐼𝑆𝐸𝑇 of size 𝑘
Proof: Assume 𝐺 has an VC of size V − 𝑘: 𝐶, consider
S = 𝑉 − 𝐶, 𝑆 = 𝑘
• Claim: 𝑆 is an independent set
22
What does poly-time mean?
Algorithm runs in time polynomial to input size.
• If the input has 𝑛 items, algorithm runs in Θ(𝑛# ) for
any constant 𝑐 is poly-time.
– Examples: intervals to schedule, number of integers to
sort, # vertices + # edges in a graph
• Numerical Value (Integer 𝑛), what is the input size?
– Examples: weights, capacity, total time, flow constraints
– It is not straightforward!
23
Real time complexity of F-F?
In class: 𝑂(𝐹( 𝑉 + 𝐸 )
• 𝑉 + 𝐸 = this much space to represent the graph
• 𝐹: size of the maximum flow.
24
What is the actual input size?
Each edge ( 𝑬 edges):
20 10
• 2 vertices: |𝑉| distinct symbol,
20 log |𝑉| bits per symbol
s t • 1 capacity: log 𝐶
10 20 Size of graph:
• 𝑂(|𝐸|(|𝑉| + log 𝐶)
– 𝑃𝑜𝑙𝑦( 𝐸 , 𝑉 , log 𝐶)
Running time:
• 𝑃𝑜𝑙𝑦( 𝐸 , 𝑉 , 𝐶 )
– Exponential if 𝐶 is exponential
25
in 𝑉 + |𝐸|
Pseudo-polynomial
Naïve Ford-Fulkerson is bad!
Problem 𝐿’s inputs contain some numerical values, say
𝑊. We need only log 𝑊 bits to store 𝑊. If algorithms runs
in 𝑃𝑜𝑙𝑦(𝑊), then it is exponential, or pseudo-
polynomial.
26
Conclusion: Reductions
• Reduction
– Construction of mapping with runtime
– Bidirectional proof
• Efficient Reduction 𝐿 ≤" 𝐾
– Which problem is harder?
– If 𝐿 is hard, then 𝐾 is hard. à Used to show hardness
– If 𝐾 is easy, then 𝐿 is easy. à Used for design algorithms
• Canonical Decision Problem
– Reduction to and from the optimization problem
• Reduction for hardness
– Independent Set ≤! Vertex Cover 27