Graph connections

Draft

P vs NP

Understand the difference between finding a solution quickly and checking a proposed solution quickly.

concept beginner complexityalgorithmsdecision-problemsnp

Hook problem

This node is about one question:

If a proposed solution can be checked quickly, does that mean a solution can also be found quickly?

To make the question concrete, use a tiny Boolean lock. It has switches x1, x2, x3, a few logic gates, and an output light. The decision question is only: does any key make the output 1?

If someone hands you one key, checking it is direct: set the switches, evaluate the gates, and read the output. This toy lock is only a local example; the topic of the node is the find-versus-check distinction.

Find a key vs try this keyThe lock has switches, gates, and an output. A proposed key can be checked directly.
switch = input bitANDORNOToutput 1 opens
x11x21x30AND1NOT1OR11

First naive idea

The most obvious way to solve a Yes/No search question is to try every candidate.

For the tiny lock, there are only eight assignments, so brute force feels harmless. That is useful for learning the shape of the problem, but it is not the lesson.

But this toy circuit can get lucky. A larger worst-case instance might hide the first accepting assignment near the end, or might have no accepting assignment at all.

Brute force can get lucky, but it has no promiseThe toy circuit opens on 000, but a worst-case search may need almost every row.
000001010011100101110111

Try a failed row such as 011 before the lucky 000 reveal. Worst-case search has no lucky-order promise.

Where it breaks

Every extra Boolean input doubles the number of candidate assignments. Checking one candidate still follows the circuit description, but finding a good candidate by blind search can explode.

The slider below uses a scaling thought experiment, not the same three-input circuit. Its point is the shape of the growth: 2^n candidates versus a polynomial-size check.

Search grows by candidates

This is a counting model for the visual; input size includes the circuit description, not just n.

not the same circuit
fixed toy circuit3 inputs · 3 gates

8 assignments, one check takes 6 simple steps

scaling thought experiment10 inputs · 20 gates

1,024 assignments, one check takes 30 simple steps

The core invention

The core idea is to separate two jobs:

  • Finding: produce a solution from scratch.
  • Checking: receive a proposed solution and verify it.

A certificate is extra evidence for a Yes answer. A verifier is the algorithm that checks that evidence. In the lock example, the certificate is one assignment, and the verifier checks the assignment format, evaluates the gates, and accepts only if the output is 1.

A certificate is one proposed Yes witnessThe assignment 110 flows through the gates and makes the output 1.
x11x21x30AND1NOT1OR11
110accepting certificate

g1=1 · g2=1 · z=1

000another opening key

g1=0 · g2=1 · z=1

011failed candidate

g1=0 · g2=0 · z=0

One failed candidate only rejects that candidate. It does not prove that no valid certificate exists.

One failed key is not a No proof011 fails, but 110 and 000 both open the same toy lock.
x10x21x31AND0NOT0OR00
110accepting certificate

g1=1 · g2=1 · z=1

000another opening key

g1=0 · g2=1 · z=1

011failed candidate

g1=0 · g2=0 · z=0

Interactive visual demo

Search scans candidates. It may get lucky, but worst-case search has no lucky-order promise.

011001010100101111110

Still checking candidates.

Decision conversion

Complexity classes usually talk about decision problems: questions with Yes/No answers. Many object-finding or optimization tasks can be converted by adding a threshold.

Turn an object-finding task into Yes/NoComplexity classes talk about decision problems, but real tasks can often be phrased with a threshold.
OptimizationFind the shortest route from A to B.
DecisionIs there a route from A to B with length <= K?
CertificateA proposed route; sum its edges and compare with K.

Formal version

Here are the definitions this node needs. They are intentionally local and enough to understand P vs NP; deeper hardness machinery belongs to later nodes.

A decision problem is a problem whose output is Yes or No.

Polynomial time means the running time is bounded by O(n^c) for some constant c, where n is the input size.

A decision problem is in P if it can be solved in polynomial time.

A decision problem is in NP if every Yes instance has a certificate whose size is polynomial in the input size, and a polynomial-time verifier can check that certificate.

For the lock example, the input size includes the lock description, not only the number of switches.

What is polynomial in what?The instance, certificate, and verifier work all have sizes.
Instance size3 inputs + 3 gates

the circuit description

Certificate size3 bits

one bit per input

Verifier steps3 bit checks + 3 gates

format check plus gate evaluation

We know P is inside NP: if you can solve the decision problem quickly, then you can also verify a Yes answer quickly by running the solver. The unknown question is whether every efficiently checkable Yes answer is also efficiently findable.

P is known to be inside NPThe unknown part is whether the boundary collapses.
NPPP = NP?NP-hard appears later; do not place it here yet.

Implementation sketch

At this level, a verifier has a simple contract: take an instance and a certificate, reject malformed certificates, and then check the claimed property in polynomial time.

type Instance = unknown;
type Certificate = unknown;

function verify(instance: Instance, certificate: Certificate): boolean {
  if (!certificateHasValidFormat(instance, certificate)) return false;
  if (!certificateSizeIsPolynomial(instance, certificate)) return false;

  return checkClaimedYesWitness(instance, certificate);
}

The figure below expands that contract for the tiny lock only: assignment format first, then gate-by-gate evaluation.

Verifier trace for the toy circuitA general verifier checks format, then evaluates gates in topological order.
Trace for assignment 110
GateInputsOutput
g1 ANDTrue, TrueTrue
g2 NOTFalseTrue
z ORTrue, TrueTrue
Malformedmissing x3 or non-bit valuereject before gates

Correctness intuition

Why is every problem in P also in NP? Build a verifier that uses an empty or dummy certificate and runs the polynomial-time solver directly.

This is not the Circuit-SAT verifier. It is a different verifier for a problem that already has a polynomial-time solver.

Why P is inside NPThis is not the circuit verifier: a P solver can ignore a dummy certificate and solve directly.
not the circuit verifier
Yes instancedummy certificate -> P solver says Yes -> accept
No instancedummy certificate -> P solver says No -> reject

Complexity

The P vs NP question is not “can brute force solve it eventually?” Brute force is an algorithm, but it may take exponential time.

The contrast is:

  • P: there is a polynomial-time way to find the Yes/No answer.
  • NP: for Yes instances, there is a polynomial-size certificate that can be checked in polynomial time.

Blind search over all assignments can take 2^n trials. One certificate check follows the input and certificate sizes.

The table is a counting model for intuition, not a full encoding-cost proof.

Search count vs one checkThe growth model is a visual counting proxy, not a full encoding-cost proof.
Scaling thought experiment, not the same circuit
n2^none check
389
101,02430
301,073,741,82490

Common confusions

NP does not mean “not polynomial.” It means Yes answers have efficiently checkable certificates.

P vs NP is an open question. This node should not imply either P = NP or P != NP.

This page only needs efficiently checkable Yes certificates. Efficiently checkable No certificates lead to other complexity classes and can wait.

NP-hard is not the same as “in NP.” Hardness is a comparison idea for another node.

Misconceptions to avoidNP is about checkable Yes certificates, not 'not polynomial'.
NP != non-polynomial

NP means Yes answers have short checkable certificates.

NP-hard != in NP

Hardness comparison comes later and is not the same as membership.

Failed key

One failed candidate only rejects that candidate, not the whole instance.

Giant table

A certificate must be polynomial-size, not an exponential lookup table.

Connections in the graph

This node is self-contained for the meaning of P, NP, and the question P = NP?.

What it does not try to prove:

  • Why particular problems are hard.
  • How reductions transfer hardness.
  • Why Circuit-SAT is a central complete problem.

Those are deeper follow-up nodes. Here, Circuit-SAT only appears as a small local example of “candidate assignment as certificate.”

Exercises

  1. Why does one accepting assignment prove a Yes answer?
  2. Why does one failed assignment not prove a No answer?
  3. What is the difference between solving a decision problem and verifying a certificate?
  4. Why is P definitely inside NP?

Graph connections : P vs NP