Graph connections

Draft

Polynomial-Time Reductions

Translate one decision problem into another while preserving Yes and No answers.

concept beginner complexityalgorithmsreductionsnp-hardness

Hook problem

Suppose you already own a fast solver for reachability when the graph is written as an adjacency map:

{ A: [B], B: [C], C: [] }, ask: can A reach C?

But the input you receive is an edge list:

[(A,B), (B,C)], ask: can A reach C?

Do you need a brand-new solver? Maybe not. You can translate the edge-list instance into the adjacency-map instance, call the solver you already trust, and return the same Yes/No answer.

Use the solver you already haveI have a solver for adjacency maps. Do I need a new solver for edge lists?
Source A: HasPathPairList[(A,B), (B,C)]Question: A -> C?source Yes
fgroup outgoing neighborspolynomial translator
Target B: HasPathAdjacencyMap{ A: [B], B: [C], C: [] }Same question: A -> C?target Yes
B solverYessame question, different encoding

This page is about that one idea: a fast, answer-preserving instance translator. The example is a format adapter, not a hardness proof.

First naive confusion

The notation will be A <=p B, read as “A reduces to B in polynomial time.” The most common early mistake is to call the wrong solver.

If A <=p B, the source instance starts in A, the translator produces a B instance, and then you need a solver for B.

Given A <=p B, which solver do you need?

This is only algorithm transfer. Hardness arrows come later.

A <=p B
Source Athe instance we must answer
ftranslate A to B
Target Bthe translated instance

Choose the solver that the translated instance will be sent to.

Translate A's instance into B, use the B solver, and return that Yes/No answer for A.

This direction is algorithm transfer. Hardness-transfer wording comes later, after the proof pipeline and cost model are visible.

Where it becomes useful

Without the translator, an edge-list reachability question looks like a new problem: write a new parser, a new traversal setup, and a new proof.

With the translator, the work becomes smaller: rearrange the same graph into the representation the existing solver expects, then reuse the solver.

Do not solve A from scratch if B already solves the translated instanceThe reduction lets a source instance travel through a target solver.
Source A: HasPathPairList[(A,B), (B,C)]Question: A -> C?source Yes
fgroup outgoing neighborspolynomial translator
Target B: HasPathAdjacencyMap{ A: [B], B: [C], C: [] }Same question: A -> C?target Yes
B solverYessame question, different encoding

The same pattern later becomes useful for difficulty evidence. Instead of proving every target problem from scratch, reductions let one doubted source problem feed several targets through translators that preserve Yes and No.

The core invention

A reduction is not a solver for the source problem. It is a function f that changes the instance format or problem setting while preserving the decision answer.

The path example should stay in your head as the main picture. The tiny arithmetic example below is only a compact mechanics fixture for the table and code sketch:

  • Source TwoNumberSum4: input a, b; ask whether a + b = 4.
  • Target TargetSum: input a, b, target; ask whether a + b = target.
  • Translator: copy a and b, then set target = 4.
Mechanics-only toy truth tableThis is a format adapter, not difficulty or hardness evidence.
Source instanceSource answerTarget instance f(x)Target answerPurpose
(1, 3)Yes(1, 3, 4)YesA normal Yes-preserving row.
(2, 2)Yes(2, 2, 4)YesMany source Yes instances can map correctly.
(1, 1)No(1, 1, 4)NoNo answers must also be preserved.
(0, 4)Yes(0, 4, 4)YesA boundary-looking row with zero.
(5, 0)No(5, 0, 4)NoAnother No row for practice.

Both Yes and No rows matter. A translator that only sends Yes instances to Yes instances is not enough.

Formal version

For decision problems A and B, we write A <=p B when there is a function f such that:

  1. f can be computed in polynomial time, measured in the source instance’s encoding length.
  2. For every source instance x, x in A iff f(x) in B.

Here in A means “is a Yes instance of problem A.” The word iff means “if and only if,” so the statement includes Yes preservation and No preservation.

The reduction is the translator fFor every source instance x, f(x) is a target instance with the same Yes/No answer.
Source A: HasPathPairList[(A,B), (B,C)]Question: A -> C?source Yes
fgroup outgoing neighborspolynomial translator
Target B: HasPathAdjacencyMap{ A: [B], B: [C], C: [] }Same question: A -> C?target Yes
B solverYessame question, different encoding
The iff contract quantifies over source instancesThe reverse direction applies to produced targets f(x), not arbitrary B instances.
Source problem A(1, 3): Yes(1, 1): No(5, 0): No
for every xx in A iff f(x) in Bx notin A iff f(x) notin B
Image of f inside B(1, 3, 4): Yes(1, 1, 4): No(5, 0, 4): No
Other B instancesnot claimed

No reverse translator from arbitrary B instances is required here.

The reverse-looking half of iff is easy to overread. It is about the paired instance f(x). It does not say every arbitrary instance of B came from A, and it does not require a reverse translator from B back to A.

Proof direction

Once A <=p B is established, a polynomial-time solver for B gives a polynomial-time solver for A:

function solveA(x: SourceInstance): boolean {
  const y = reduceAtoB(x);
  return solveB(y);
}

The source solver has exactly four jobs: receive x, compute f(x), call the target solver, and return the same Yes/No answer.

Proof pipeline: a B solver becomes an A solver

Step through the same path-encoding example used in the hook.

1 / 4
Receive x in AReceive the edge-list reachability instance.source Yes
Compute f(x)Group outgoing neighbors by source node to build the adjacency map.
Call B solverRun the existing adjacency-map reachability solver.target Yes
Return same answerReturn the same answer for the original edge-list instance.source Yestarget Yes

Receive the edge-list reachability instance.

Receive x in AReceive the edge-list reachability instance.
Compute f(x)Group outgoing neighbors by source node to build the adjacency map.
Call B solverRun the existing adjacency-map reachability solver.
Return same answerReturn the same answer for the original edge-list instance.

Implementation sketch

For the arithmetic mechanics-only fixture, the translator is deliberately small:

function reduceTwoNumberSum4ToTargetSum(source: { a: number; b: number }) {
  return { a: source.a, b: source.b, target: 4 };
}

The code is not proving anything hard. It only makes the reduction contract testable: every fixture row has sourceAnswer(x) === targetAnswer(f(x)).

Proof stepCode responsibility
receive-sourceaccept one source instance x
compute-targetcompute y = f(x) in polynomial time
solve-targetcall the solver for problem B on y
return-answerreturn that same Yes/No answer for x

Correctness intuition

Correctness is the reason the last line may return the target answer as the source answer.

If x is a Yes instance of A, then f(x) is a Yes instance of B. If x is a No instance of A, then f(x) is a No instance of B. The target solver’s answer on f(x) is therefore exactly the answer we needed for x.

The iff contract quantifies over source instancesThe reverse direction applies to produced targets f(x), not arbitrary B instances.
Source problem A(1, 3): Yes(1, 1): No(5, 0): No
for every xx in A iff f(x) in Bx notin A iff f(x) notin B
Image of f inside B(1, 3, 4): Yes(1, 1, 4): No(5, 0, 4): No
Other B instancesnot claimed

No reverse translator from arbitrary B instances is required here.

Notice what is not being promised: the target solver might know many B instances that were never produced by this translator. Those unrelated instances are outside this reduction’s correctness claim.

Complexity

The translator must be fast, and its output must not hide exponential work in a giant target instance.

In the model below, source encoding length is n, translator work is n^2, the mapped target encoding length is at most n^2, and the target solver takes the cube of the target encoding length. The total is n^2 + (n^2)^3 = n^2 + n^6, still polynomial.

Polynomial translator plus polynomial solver stays polynomialThis simple model keeps target size <= n^2, translator work n^2, and target solver time targetSize^3.
ntranslator worktarget encoding lengthtarget solver timecombined time
5252515,62515,650
101001001,000,0001,000,100
30900900729,000,000729,000,900
mapped size is polynomially boundedn^2 + (n^2)^3 = n^2 + n^6

The input size is the encoded description length, not the numeric magnitude of a value written in the input. This is why the arithmetic toy is only a mechanics example.

Hardness preview

The proof above says: A <=p B plus a fast solver for B gives a fast solver for A.

The preview version for hardness evidence uses the same sentence backward as a thought experiment: if a fast solver for B existed, the reduction would give a fast solver for A; therefore any reason to doubt fast solvers for A also applies to B.

Hardness preview comes after algorithm transferThis is beginner wording only. The formal NP-hardness definition belongs to the next node.
Valid preview: A <=p BIf B had a fast solver, A would get one too; doubts about fast solvers for A now apply to B.If fast B, then fast A.
Wrong arrow: B <=p AThis arrow only says B can use an A solver. It does not transfer doubt from A to B.Does not prove B hard.

This page does not prove P != NP, define NP-hardness formally, or claim the toy examples are hard.

Named chain preview

Later nodes will instantiate the same preservation contract with real constructions:

Later lecture chains reuse the same preservation contractThese are previews only, without construction details on this page.
Without reductionsEach target needs a from-scratch argument.
With reductionsOne doubted source can feed several targets through answer-preserving translators.
Circuit-SAT <=p SATcircuit satisfiable iff formula satisfiable
SAT <=p 3SATformula satisfiable iff 3CNF satisfiable
3SAT <=p Clique3SAT formula satisfiable iff graph has a k-clique

The arrows above are only a map. The construction details belong to those later nodes.

Common confusions

Invalid shortcuts to reject

A reduction needs both the answer-preservation contract and the polynomial-time translator contract.

One-way implication is not enough
missing-reverse-direction

Two Yes rows preserve Yes, but one No source row becomes target Yes. That is not iff.

Yes -> Yes: Yes still YesYes -> Yes: Yes still YesNo -> Yes: Broken: No became Yes
Exponential translatorReveal invalid state
Solving inside the translatorReveal invalid state
Wrong hardness arrowReveal invalid state
Solution object vs Yes/No answerReveal invalid state

Keep these boundaries in mind:

  • A <=p B means a solver for B can help solve A.
  • A reduction preserves decision answers, not necessarily witness objects.
  • A translator that performs an exponential search is not a polynomial-time reduction.
  • A toy format adapter can teach mechanics without proving hardness.

Connections in the graph

P vs NP supplies the vocabulary of decision problems and polynomial time. This node adds the comparison tool: fast, answer-preserving translations between decision problems.

Local graph positionThis is a page-local learning map; the faded future node is not a graph edge yet.
p-vs-npdecision problems and polynomial time
->implemented graph edge
polynomial-time-reductionsanswer-preserving translators
->future follow-up
np-hardnessnot yet implemented

The next planned node, np-hardness, will name the formal hardness-transfer rule. It is not linked as a route yet because that node does not exist in the site.

Exercises

Practice the contract

Each card uses one deterministic fixture from the page.

The edge list [(A,B), (B,C)] asks whether A reaches C. After translation, the adjacency map asks the same reachability question. Is the answer preserved?

Choose an answer to reveal the check.

For the mechanics-only toy row (1,1), the source asks 1 + 1 = 4 and the target asks 1 + 1 = target 4. What must happen?

Choose an answer to reveal the check.

Given A <=p B, which solver can you use to solve A after translation?

Choose an answer to reveal the check.

If n = 10, translator work is n^2 and the target encoding length is n^2. Is the composed solver still polynomial?

Choose an answer to reveal the check.

  1. In A <=p B, why does the solver call go to B?
  2. Why must No instances be preserved, not only Yes instances?
  3. Why is an exponential translator invalid even if the target solver is fast?
  4. What exactly is claimed about target instances outside the image of f?

Graph connections : Polynomial-Time Reductions