0% found this document useful (0 votes)
17 views

Lecture 24

The document summarizes reductions between several NP-complete problems including Hamiltonian Cycle, Hamiltonian Path, Longest Simple Cycle, Longest Simple Path, 3-CNF, MAX 2SAT, Clique, Vertex Cover, Independent Set, Set Cover, Dominating Set, Subset Sum, Set Partition, and 0-1 Knapsack. It proves several problems like Hamiltonian Path, Longest Simple Path, and 0-1 Knapsack are NP-complete by reducing other known NP-complete problems like Hamiltonian Cycle, Longest Simple Cycle, and Set Partition to them respectively in polynomial time.

Uploaded by

f20201862
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lecture 24

The document summarizes reductions between several NP-complete problems including Hamiltonian Cycle, Hamiltonian Path, Longest Simple Cycle, Longest Simple Path, 3-CNF, MAX 2SAT, Clique, Vertex Cover, Independent Set, Set Cover, Dominating Set, Subset Sum, Set Partition, and 0-1 Knapsack. It proves several problems like Hamiltonian Path, Longest Simple Path, and 0-1 Knapsack are NP-complete by reducing other known NP-complete problems like Hamiltonian Cycle, Longest Simple Cycle, and Set Partition to them respectively in polynomial time.

Uploaded by

f20201862
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

BITS, PILANI – K. K.

BIRLA GOA CAMPUS

Design & Analysis of Algorithms


(CS F364)

Lecture No. 24

1
NP Complete Problems
We have proved the following reductions:
CIRCUIT-SAT Hamiltonian Cycle

SAT Longest Simple Cycle TSP

3-CNF

MAX 2SAT k-CNF Max k-CNF Clique

Vertex Cover

Independent Set Set Cover Dominating Set


Hamiltonian Path
Theorem
Hamiltonian Path is NP Complete.
Proof
We prove Hamiltonian Cycle ≤p Hamiltonian Path
Hamiltonian Path
Construction
Given an instance 𝐺 = 〈𝑉, 𝐸〉 of the Hamilton Cycle
problem
Construct a new graph 𝐺′ by adding three new vertices
“Start”, “AlmostThere”, and “Finish”.
The vertex “Start” connects to an arbitrary vertex 𝑣 in 𝑉
“AlmostThere” connects to every vertex in 𝑉 that are
adjacent to 𝑣
and “Finish” connects to “AlmostThere”.
Clearly this reduction is in polynomial time.
Hamiltonian Path
Claim:
𝐺 has a Hamilton Cycle if and only if 𝐺′ has a Hamilton
Path.
Suppose 𝐺 has a Hamiltonian cycle.
Without loss of generality, suppose the cycle is 𝑣1 → 𝑣2
→ ⋯ → 𝑣𝑛 → 𝑣1
And suppose Start connects to 𝑣1 in 𝐺 ′ .
Then, the following path is a Hamiltonian path in 𝐺 ′ :
𝑆𝑡𝑎𝑟𝑡 → 𝑣1 → 𝑣2 → ⋯ → 𝑣𝑛 → 𝐴𝑙𝑚𝑜𝑠𝑡𝑇ℎ𝑒𝑟𝑒 →
𝐹𝑖𝑛𝑖𝑠ℎ
Hamiltonian Path
Conversely,
Suppose 𝐺 ′ has a Hamiltonian path.
Then the path must start with 𝑆𝑡𝑎𝑟𝑡 → 𝑢 and
finish with 𝑣 → 𝐴𝑙𝑚𝑜𝑠𝑡𝑇ℎ𝑒𝑟𝑒 → 𝐹𝑖𝑛𝑖𝑠ℎ.
But, 𝑣 has an edge 𝑒 connected to 𝑢.
The path from 𝑢 to 𝑣, plus this edge 𝑒 form a
Hamiltonian cycle of 𝐺.
Hamiltonian
Exercise:
1. Longest Simple Cycle is NP Complete
2. Longest Simple Path is NP Complete
Subset Sum
Subset Sum
• Given a set A of integers and an integer number S,
does there exist a subset of A such that the sum of
its elements is equal to S?
Theorem:
SUBSET SUM is NP-complete.
Assume for now
Set-Partition
Set Partition Problem
Given a set S of integers.
Does there exist an set A  S such that

෍𝒂 = ෍ 𝒂
𝒂∈𝑨 𝒂∈𝑺−𝑨

In other words, is there a way to partition 𝑺 into two


parts, so that both parts have equal sum?
Set-Partition
Theorem:
SET-PARTITION is NP-Complete
Proof:
• SET-PARTITION ∈ NP:
Guess the two partitions and verify that the two have
equal sums, This can be done in polynomial time.
• Claim
SUBSET-SUM ≤𝑷 SET-PARTITION
Set-Partition
Reduction Algorithm:
Given instance (X, t) of Subset Sum
Let s be the sum of members of X.
Let X’ = X  {s – 2t}
This can be done in polynomial (linear) time.
Claim:
〈X, t〉∈ SUBSET-SUM iff〈X′〉∈ SET-PARTITION
That is, X has a subset that sums to t ⇔ X’ can be
partitioned into two sets with equal sums
Note: The sum of members of X′ is 2s−2t.
Set-Partition
Suppose there exists a set (say Y) of numbers in X that
sum to t.
Then the set of remaining numbers in X sum to s−t.
Let Y’ = Y  {s – 2t}
Then Y’  X’ such that σ𝒂∈𝒀′ 𝒂 = σ𝒂∈𝑿′ −𝒀′ 𝒂

=𝒔−𝒕
Therefore, there exists a partition of X′ into two such
that each partition sums to s−t
Set-Partition
Conversely, suppose there exists a partition of X′ into
two sets such that the sum over each set is s−t.
Then, one of these sets contains the number s−2t.
Removing this number, we get a set of numbers whose
sum is t, and all of these numbers are in X
0-1 Knapsack problem
0-1 Knapsack Decision Problem
Given n items with weights w1, w2,……, wn
and values v1, v2,……, vn and capacity W and value V
Is there a subset S ⊆ {1,2, .., n} such that
σ𝒊 ∈ 𝑺 𝒘𝒊 ≤ 𝑾 and σ𝒊 ∈ 𝑺 𝒗𝒊 ≥ 𝐕?

Theorem:
0-1 Knapsack Problem is NP-complete
0-1 Knapsack problem

Proof:
• 0-1 Knapsack is in NP.
The proof is the set S of items that are chosen and the
verification process is to computeσ𝒊 ∈ 𝑺 𝒘𝒊 and σ𝒊 ∈ 𝑺 𝒗𝒊
This can be done in polynomial time in the size of input
• Claim
Set-Partition ≤𝑷 0-1 Knapsack
0-1 Knapsack problem
Reduction Algorithm Q:
Suppose we are given a set X = {a1, a2,……, an} for the
Set-Partition Problem
Consider the following Knapsack problem:
wi = ai & vi = ai for i = 1,2,…,n &
𝟏 𝒏
𝑾=𝑽= σ 𝒂
𝟐 𝒊=𝟏 𝒊
This process of converting the Set-Partition problem to
0-1 Knapsack problem is polynomial in the input size.
0-1 Knapsack problem
Suppose X is a ‘Yes’ instance for the Set-Partition
problem.
Then there exists a subset S of X such that
𝟏
σ𝒊 ∈ 𝑺 𝒂𝒊 = σ𝒊 ∈𝑿−𝑺 𝒂𝒊 = σ𝒏𝒊=𝟏 𝒂𝒊
𝟐
Let our Knapsack contain the items in S
𝟏 𝒏
Then σ𝒊 ∈ 𝑺 𝒘𝒊 = σ𝒊 ∈ 𝑺 𝒂𝒊 = σ𝒊=𝟏 𝒂𝒊 = W
𝟐
𝟏 𝒏
And σ𝒊 ∈ 𝑺 𝒗𝒊 = σ𝒊 ∈ 𝑺 𝒂𝒊 = σ𝒊=𝟏 𝒂𝒊 = V
𝟐
0-1 Knapsack problem
Conversely, Suppose Q(X) is a ‘Yes’ instance for the 0-1
Knapsack problem
Let S be the set chosen for the 0-1 Knapsack problem
𝟏
We have σ𝒊 ∈ 𝑺 𝒘𝒊 = σ𝒊 ∈ 𝑺 𝒂𝒊 ≤ W = σ𝒏𝒊=𝟏 𝒂𝒊 and
𝟐
𝟏 𝒏
σ𝒊 ∈ 𝑺 𝒗𝒊 = σ𝒊 ∈ 𝑺 𝒂𝒊 ≥ V = σ 𝒂
𝟐 𝒊=𝟏 𝒊
𝟏 𝒏
Thereforeσ𝒊 ∈ 𝑺 𝒂𝒊 = σ𝒊 ∈ 𝑿 − 𝑺 𝒂𝒊 = σ𝒊=𝟏 𝒂𝒊
𝟐
Thus S is the required subset of X.

You might also like