Sub topic 14
From Yes/No Answers to Actual Solutions
This chapter assumes you already know Turing (oracle) reductions, the definition of NP-completeness, and the Independent Set problem from earlier chapters. It also assumes you can read basic Python.
The gap between deciding and finding
A decision procedure for Independent Set only answers "yes" or "no" to the question "Does G have an independent set of size k?" In practice you usually want the set itself. That task is the search version of the problem. A problem is self-reducible when its search version reduces in polynomial time to its decision version. In other words, a yes/no oracle is enough to build an actual solution.
This is a Turing reduction, not a many-one reduction. The search algorithm calls the oracle many times, and each query depends on the answers to earlier ones.
Shrinking the graph with an oracle
The strategy is to delete vertices one at a time. After each deletion, ask the oracle whether a size-k independent set still exists. If it does, the vertex was not needed and stays deleted. If it does not, put the vertex back.
from itertools import combinations
def brute_has_is(vertices, edges, k):
# Stand-in decision oracle (exponential time, for demonstration only)
present = {frozenset(e) for e in edges}
return any(all(frozenset(p) not in present for p in combinations(c, 2))
for c in combinations(vertices, k))
def find_independent_set(vertices, edges, k, has_is):
# has_is(vertices, edges, k) -> bool is a decision oracle
if not has_is(vertices, edges, k):
return None
chosen = list(vertices)
for v in list(vertices):
trial = [u for u in chosen if u != v]
trial_edges = [(a, b) for a, b in edges
if a in trial and b in trial]
if has_is(trial, trial_edges, k):
chosen = trial
return chosen # exactly k vertices, pairwise non-adjacent
print(find_independent_set([1, 2, 3, 4], [(1, 2), (2, 3), (3, 4)], 2, brute_has_is))
# [2, 4]Why it is correct
The loop keeps one invariant: the current graph always contains an independent set of size k. Let I be such a set in the final graph. Suppose some vertex v in the final graph is not in I. When the loop tested v, the graph at that point contained every final vertex. Removing v would therefore still leave I intact, so the oracle would have answered yes and v would have been deleted. That contradicts v being in the final graph. So the final graph is exactly I: it has k vertices and no edges among them.
Cost
The algorithm makes at most |V| + 1 oracle calls. Each query is a subgraph of G, so every query is a valid instance no larger than the input. If the oracle ran in polynomial time, the whole search would also run in polynomial time.
| Version | Question | Output |
|---|---|---|
| Decision | Is there an independent set of size k? | yes / no |
| Search | Find one | a set of k vertices |
Exercise
Describe a search-to-decision algorithm for SAT that uses at most n + 1 oracle calls on a formula with n variables, and explain why it is correct.
Show answer
First ask whether the formula F is satisfiable. If not, stop. Otherwise, for i = 1 to n, set xi = true, simplify F, and ask the oracle. If it answers yes, keep xi = true. If it answers no, set xi = false. That choice must work, because the formula was satisfiable before xi was fixed, so one of the two values keeps it satisfiable. The invariant "the formula is satisfiable under the partial assignment" holds at every step. After n steps the full assignment satisfies F, using 1 + n calls.
Exercise
In findindependentset, why can the oracle never answer no on the very last vertex of a graph that already has exactly k vertices forming an independent set?
Show answer
It can answer no, and it must. Removing any vertex leaves only k − 1 vertices, which cannot contain an independent set of size k. The oracle says no, the vertex is restored, and the k-vertex set is returned unchanged.