Attic › Computer science › NP (complexity)

A nondeterministic machine solves NP problems quickly by guessing the right path

The name NP stands for nondeterministic polynomial time. It comes from an equivalent way to define the class: a problem is in NP if a theoretical computer called a nondeterministic Turing machine can solve it in polynomial time.

A standard computer is a deterministic Turing machine. At each step of a calculation, its rules and current state dictate one exact next step. If it faces a choice of paths—such as which number to put in an empty Sudoku square—it must test them one after another.

A nondeterministic machine can explore multiple paths at the same time. When a nondeterministic algorithm reaches a choice, it branches into parallel copies of itself, and each copy follows a different path. If at least one branch reaches a valid "yes" answer, the whole machine accepts the answer as "yes". You can also think of this machine as a lucky guesser that always chooses the correct path on its first try.

Solving a problem in polynomial time on a nondeterministic machine is mathematically the same as verifying a certificate in polynomial time on a standard, deterministic machine:

1. From verifying to guessing: If a standard machine can check a certificate in polynomial time, a nondeterministic machine can solve the problem from scratch. It uses its branching ability to guess all the characters of the certificate in polynomial time, and then runs the standard verification steps on each branch.

2. From guessing to verifying: If a nondeterministic machine can solve a problem in polynomial time, the sequence of choices that leads to the "yes" branch has a polynomial length. A standard machine can use a record of those exact choices as a certificate, following that single path to verify the answer in polynomial time.

Nondeterministic Turing machines do not exist in the physical world. Real computers cannot create infinite parallel copies of themselves for free, and they cannot see the future to guess the right path. Instead, computer scientists use these machines as a mathematical model to measure how hard a problem is.

Fact-checked against NP (complexity) on Wikipedia

Part of the Computer science syllabus: Computational Complexity

See it on the timeline of Computer science