Set partition is NP complete
Last Updated :
02 Nov, 2023
Set partition problem: Set partition problem partitions an array of numbers into two subsets such that the sum of each of these two subsets is the same. Let S be a set of numbers and A is a subset of numbers with sum S1, then there exists another subset containing the remainder of the elements (S - A) with sum S2, and S1 is equaled to S2.
Problem Statement: Given a set S of N numbers, the task is to determine if the set contains two partitions of S, with both of them having exactly the same sum.
Explanation:
An instance of the problem is an input specified to the problem. An instance of the Set Partition problem is a set S, and the task is to check whether there exist any two non-overlapping partitions of S having a sum of elements as sum. Since an NP-Complete problem is a problem which is both in NP and NP-hard, the proof for the statement that a problem is NP-Complete consists of two parts:
- The problem itself is in NP class.
- All other problems in NP class can be polynomial-time reducible to that. (B is polynomial-time reducible to C is denoted as B ≤ PC)
If the 2nd condition is only satisfied then the problem is called NP-Hard.
But it is not possible to reduce every NP problem into another NP problem to show its NP-Completeness all the time. Therefore, to show a problem is NP-Complete then prove that the problem is in NP and any NP-Complete problem is reducible to that i.e., if B is NP-Complete and B ≤ PC For C in NP, then C is NP-Complete. Thus, it can be concluded that the Set partition problem is NP-Complete using the following two propositions:
Set Partition Problem is in NP:
If any problem is in NP, then, given a ‘certificate’, which is a solution to the problem and an instance of the problem (a set S and two partitions A and A’, in this case), it can be proved that the certificate in polynomial time. This can be done in the following way:
- For every element x in A and x’ in A’, verify that all the elements belonging to S are covered.
- Let S1 is 0, S2 is 0
- For every element x in A add that value to S1.
- For every element x’ in A’ add that value to S2.
- Verify that S1 is the same as S2.
The algorithm takes linear time in the size of the set of numbers.
Set Partition Problem is NP-Hard:
In order to prove that the Independent Set problem is NP-Hard, perform a reduction from a known NP-Hard problem to this problem. Carry out a reduction from which the Subset Sum Problem can be reduced to the Set Partition problem. The Subset Problem provides the input as a set of numbers S and a target sum t, the problem aims at finding the subset T belonging to S with a sum same as the t. Let s be the sum of members of S. Now, feed S' = S ∪ {s − 2t} into the Set Partition problem.
Now prove that the problem of computing the set partition indeed boils down to the computation of the subset-sum. The reduction can be proved by the following two propositions:
Now, let us consider a set of the numbers T with summation equivalent to t(Subset Sum), then the remainder of the elements in S(assuming O) will have the sum o = s - t. Let us assume the original set is equal to T’ = T ∪ (s - 2t) which has a sum equal to t’.
Now the following observations hold:
o = s - t
o - t = s - 2t, Difference in sum between O and T.
t’ = t + (s - 2t)
= s - t
= o, the sum of T' and O are equal.
Hence, the original set can be partitioned into two subsets of sum (s - t) each. Therefore, the set partition problem is satisfied.
Now suppose an equal-sum partitioning (A, A') of S' = S ∪ {s − 2t} exists. The sum of each partition is given by:
a = \frac{s + (s - 2*t)}{2} = (s - t)
Consider the partition containing the element {s - 2t} to be A'. Let A = A’- {s - 2t}. The sum of elements in A is given by:
A = s - t - {s - 2t}
= t
Also, S’ - S = {s - 2t}. So A is a subset of S with a sum equal to t.
Therefore, the subset sum problem is satisfied.
Similar Reads
P, NP, CoNP, NP hard and NP complete | Complexity Classes In computer science, problems are divided into classes known as Complexity Classes. In complexity theory, a Complexity Class is a set of problems with related complexity. With the help of complexity theory, we try to cover the following.Problems that cannot be solved by computers.Problems that can b
5 min read
Introduction to NP-Complete Complexity Classes NP-complete problems are a subset of the larger class of NP (nondeterministic polynomial time) problems. NP problems are a class of computational problems that can be solved in polynomial time by a non-deterministic machine and can be verified in polynomial time by a deterministic Machine. A problem
5 min read
NP-Hard Class A 'P' problem is said to be NP-Hard when all 'Q' belonging in NP can be reduced in polynomial time (n^k where k is some constant) to 'P' assuming a solution for 'P' takes 1 unit time. NP-Hard is a computational complexity theory that acts as a defining property for the class of problems that are "at
2 min read
Difference between NP hard and NP complete problem All NP Complete Problems are NP-Hard but vice versa is not true. NP-Complete problems are subset of NP Problems. NP Problems : NP problems are a class of computational problems that can be solved in polynomial time by a non-deterministic machine and can be verified in polynomial time by a determinis
2 min read
NP-Complete Complexity Proofs
Proof that Clique Decision problem is NP-Complete Prerequisite: NP-Completeness A clique is a subgraph of a graph such that all the vertices in this subgraph are connected with each other that is the subgraph is a complete graph. The Maximal Clique Problem is to find the maximum sized clique of a given graph G, that is a complete graph which is a s
4 min read
Proof that Independent Set in Graph theory is NP Complete Prerequisite: NP-Completeness, Independent set. An Independent Set S of graph G = (V, E) is a set of vertices such that no two vertices in S are adjacent to each other. It consists of non- adjacent vertices. Problem: Given a graph G(V, E) and an integer k, the problem is to determine if the graph co
5 min read
Prove that a problem consisting of Clique and Independent Set is NP Complete Prerequisite: NP-Completeness, NP Class, Clique, Independent Set Problem: Given an undirected graph G = (V, E) and an integer K, determine if a clique of size K as well as an independent set (IS) of size K, exists. Demonstrate that it is an NP Complete. Explanation: A Clique is a subgraph of a graph
6 min read
Prove that Dense Subgraph is NP Complete by Generalisation Prerequisites: NP-Completeness, NP Class, Dense Subgraph Problem: Given graph G = (V, E) and two integers a and b. A set of a number of vertices of G such that there are at least b edges between them is known as the Dense Subgraph of graph G. Explanation: To prove the Dense Subgraph problem as NP-c
3 min read
Prove that Sparse Graph is NP-Complete Prerequisite: NP-Completeness, NP Class, Sparse Graph, Independent Set Problem: Given graph G = (V, E) and two integers a and b. A set of a number of vertices of G such that there are at most b edges between them is known as the Sparse Subgraph of graph G. Explanation: Sparse Subgraph problem is def
4 min read