Definition
Star Sum Problem
Let
be a graph consisting of a set of vertex-disjoint stars and let be a target integer. The star sum problem is a decision problem asking whether there exists a subset of stars in such that the total number of vertices in is precisely . Example Instance: Below is a graph
made of 4 disjoint stars ( to ) and a target integer . A valid solution subset would be since , or since .
Relation to Subset Sum
The star sum problem is essentially a graph-theoretic formulation of the subset sum problem. Because the stars are strictly vertex-disjoint, the structural properties of the stars (such as their edges) are irrelevant; each star
Consider a concrete instance where we want to find a subset summing to
Equivalence to Subset Sum Problem
The star sum problem is equivalent (w.r.t. polynomial time reduction) to the subset sum problem. Therefore, it is also NP-complete.
Let an instance of the subset sum problem be given by a multiset of positive integers
and a target sum . In polynomial time, we construct a graph
as follows: for each integer , create a star graph component with exactly vertices (which corresponds to the complete bipartite graph , or if ). All constructed stars are strictly vertex-disjoint. We keep the same target integer . Correctness: Picking a subset of stars in
whose vertices sum to exactly directly corresponds to picking a subset of integers in that sum to exactly .
Let an instance of the star sum problem be given by a graph
consisting of vertex-disjoint stars and a target . In polynomial time, count the number of vertices
for each star in . We construct a subset sum instance with the multiset and the same target sum . Correctness: Picking a subset of integers from
summing to exactly identically mirrors selecting the corresponding stars in to obtain exactly vertices.
Approaches
Since the problem is a direct mapping to the subset sum problem, the exact same algorithmic approaches apply:
Brute-force
A brute-force approach evaluates all possible
Dynamic Programming
The problem can be solved in pseudo-polynomial time using dynamic programming.
Algorithm:
Given a collection of
- Initialisation: Start by marking all stars as “unprocessed” and construct an empty list (or set)
of integers.
Intuition: We will process the stars one by one and keep track of all possible numbers we could get by choosing any subset of them. Observe that while the number of possible choices ofcan be , the number of possible numbers we can get is bounded. - Iteration: Repeatedly process unprocessed stars (in an arbitrary order) as follows:
- Choose an unprocessed star and read the number of its vertices (say it is
). - Construct
by having it contain the increment of by . - Update
by setting .
- Choose an unprocessed star and read the number of its vertices (say it is
- Termination: After all stars are processed, output YES if and only if
contains .
Visual Step-by-Step Example:
Consider
Time complexity:
Why is this Dynamic Programming?
While it may look like we are simply building a set, this procedure is fundamentally a dynamic programming approach. It incrementally constructs a table of boolean values where the state is “can we reach sum
using a subset of the first stars?“. Specifically, keeping track of the achievable sums in the set
after processing stars is mathematically identical to storing a boolean array DP[i][j](which isTrueif sumis achievable using the first stars). The transition directly corresponds to the DP recurrence DP[i][j] = DP[i-1][j] OR DP[i-1][j-c]. By only keeping track of the “True” values in a set(which bounds our runtime), we optimize the sparse DP table.
Constructing the Solution (Witness):
Once we know that the target sum
1. Backtracking: Once we find
2. Explicit Storage: Alternatively, for each intermediate sum
This approach makes returning the final solution completely trivial (just look up the set for key