4.6.23Theory of Computation

NP — non-deterministic polynomial, verifier definition

2,042 words9 min readdifficulty · medium

WHAT is NP?

Two equivalent views — both are NP, and proving them equal is a standard exercise:

  1. Verifier view (the practical one): "yes" instances have a short certificate that a fast checker accepts.
  2. Nondeterministic machine view (the name's origin): a nondeterministic Turing machine that can guess and runs in polynomial time, accepting if some computation branch accepts.

WHY does the definition look like that? (Derivation from first principles)

We want to formalize "easy to check." Start from the raw idea and force each piece:

Step 1 — We need an extra piece of information (the certificate). Why? "Checking a solution" requires the solution to check. For "Is this graph 3-colorable?", the certificate is a coloring. Without cc you'd be back to solving, not checking. So we introduce c\exists c.

Step 2 — The certificate must be short: cp(x)|c| \le p(|x|). Why? If we allowed certificates of, say, exponential length, the verifier couldn't even read them in polynomial time, and any problem would trivially "qualify." Bounding c|c| by a polynomial in x|x| keeps the proof reasonably sized.

Step 3 — The verifier VV must run in polynomial time. Why? "Easy to check" must literally mean fast. Polynomial time is our robust notion of "feasible." A slow checker would let hard problems sneak in.

Step 4 — One-sided existence: only "yes" needs a certificate. Why? xL    c(V(x,c)=1)x\in L \iff \exists c\,(V(x,c)=1). For "no" instances, no certificate works — there's nothing to show. This asymmetry is why NP and co-NP are believed different.

Putting Steps 1–4 together is the definition. Nothing was assumed; each clause is the minimal fix for a concrete loophole.


HOW to prove a problem is in NP (a recipe)

To show LL \in NP, answer three questions:

  1. What is the certificate? (the "guessed" object)
  2. Why is it polynomially short? (cp(x)|c|\le p(|x|))
  3. How does VV check it in poly time?

Relationships you must know

  • PNP\text{P} \subseteq \text{NP} (proven above).
  • NPEXP\text{NP} \subseteq \text{EXP}: brute-force all certificates of length p(x)\le p(|x|); there are at most 2p(x)2^{p(|x|)} of them, each checked in poly time \Rightarrow exponential overall.
  • Whether P=NP\text{P}=\text{NP} is open (the famous million-dollar question).

Common mistakes (Steel-manned)


Recall Feynman: explain it to a 12-year-old

Imagine a treasure hunt over a huge island. Finding the treasure could take you forever — there are millions of spots. But if your friend says "dig under the big oak tree by the river," you can run there and check in five minutes. NP problems are the treasure hunts where checking a tip is quick, even if searching from scratch is brutal. The "tip" is the certificate. NP doesn't promise the hunt is fast — only that verifying the answer is.


Flashcards

What does NP stand for (literally)?
Nondeterministic Polynomial time — NOT "non-polynomial."
Define NP via verifiers.
LL\inNP iff there's a poly-time verifier VV and polynomial pp s.t. xL    c, cp(x), V(x,c)=1x\in L \iff \exists c,\ |c|\le p(|x|),\ V(x,c)=1.
What three properties must a certificate/verifier satisfy?
Certificate is polynomially short; verifier runs in poly time; certificate exists iff the instance is a "yes."
Why is NP's definition one-sided?
Only "yes" instances need a certificate; for "no" instances NO certificate makes VV accept (the symmetric version is co-NP).
Certificate for SAT?
A satisfying truth assignment; verify by evaluating the formula (poly time).
Certificate for Hamiltonian Cycle?
A permutation of all vertices; verify each consecutive pair (and wrap-around) is an edge and all vertices appear once.
Certificate for COMPOSITE?
A nontrivial factor dd, 1<d<N1<d<N; verify Nmodd=0N \bmod d = 0.
Why is P \subseteq NP?
A poly-time solver acts as a verifier that ignores the certificate and re-solves the problem.
Why is NP \subseteq EXP?
Brute-force all 2p(x)\le 2^{p(|x|)} certificates, checking each in poly time.
How do the verifier and nondeterministic-machine views connect?
The nondeterministic guess written down IS the certificate; the deterministic check after guessing IS the verifier.
Is "nondeterministic" the same as "random"?
No — nondeterminism accepts if SOME branch accepts (an OR); randomness uses probabilities/majority.

Connections

  • P (complexity class) — the "solve fast" sibling; P \subseteq NP.
  • co-NP — the mirror class with short certificates for "no" instances.
  • NP-Completeness — hardest problems in NP via Polynomial-Time Reductions.
  • Cook–Levin Theorem — SAT is NP-complete; ties this note to the verifier idea.
  • Nondeterministic Turing Machine — the machine model behind the name.
  • Boolean Satisfiability (SAT) — canonical NP example used above.
  • P vs NP Problem — the open question this whole class orbits.

Concept Map

captured by

equivalent view A

equivalent view B

needs

guesses

bounded by

is a

only yes needs

contrasts with

ensures V can read c

together form

plugged into

NP class

Hard to solve easy to check

Verifier definition

Nondeterministic TM

Certificate c

Short size |c| le p of |x|

Poly-time checker V

One-sided existence

co-NP

Defining biconditional

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, NP ka matlab "Non-Polynomial" NAHI hai — yeh ek bahut common galatfehmi hai. NP ka matlab hai Nondeterministic Polynomial. Asli idea simple hai: kuch problems aise hote hain jahan solution dhoondhna mushkil ho sakta hai, lekin agar koi tumhe ek possible answer (jise hum certificate ya proof kehte hain) de de, to tum use jaldi check kar sakte ho. Jaise Sudoku solve karna time leta hai, par bhara hua Sudoku check karna 1 minute ka kaam hai. Bas yahi asymmetry NP capture karta hai.

Formal definition yeh hai: ek problem LL NP mein hai agar ek verifier VV exist karta hai jo polynomial time mein chalta hai, aur har "yes" input xx ke liye ek chhota certificate cc hota hai (length polynomial ke andar) jisse V(x,c)=1V(x,c)=1 ho jaata hai. Important baat — yeh one-sided hai: sirf "yes" cases ke liye certificate chahiye. "No" cases ke liye guarantee bas itni hai ki koi bhi certificate kaam nahi karega. SAT mein certificate hota hai ek satisfying assignment, Hamiltonian cycle mein ek vertices ka order, aur composite number mein ek factor.

Yeh isliye important hai kyunki poori complexity theory ka dil yahi hai — P vs NP ka million-dollar sawaal. P matlab "jaldi solve ho jaaye", NP matlab "jaldi check ho jaaye". P hamesha NP ke andar hai (solver khud hi ek lazy verifier ban jaata hai). Lekin kya har jaldi-check-hone-wali problem jaldi solve bhi ho sakti hai? Yeh aaj tak koi nahi jaanta. Exam mein jab bhi poochhe "prove karo ki X NP mein hai", to bas teen sawaal answer karo: certificate kya hai, woh short kyun hai, aur verifier use poly-time mein kaise check karta hai.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections