P vs NP
A while ago, OpenAI claimed to have solved the Navier-Stokes problem, which sparked a lot of discussion on Twitter and in the math community. I’m not going into that here, but it’s one of the seven Millennium Prize Problems. Looking through that list, I came across P vs NP again.
One of my favorite classes, if not my favorite, during undergrad at UT was Algorithms. We started with basic algorithms and later got into proofs and more advanced concepts. P vs NP was one of the topics I found most interesting. I realized I’d forgotten a lot of it, along with a lot about proofs and logical reasoning, so I went down a rabbit hole.
Before getting into P vs NP, let’s talk about a dinner party.
Who sits next to who?
I’m having friends over for dinner, and everyone needs a seat around the same table. If nobody minds who they sit next to, I can go through the names and give each person a chair.
Now suppose some pairs don’t get along. I want everyone at the table, but those pairs can’t sit beside each other. The table is round, so the last person in my list sits next to the first too.
Try seating the guests yourself, then check who ends up beside who. Can you rearrange them so everyone gets along with both neighbors? Add guests to see how the number of arrangements grows.
Seat everyone
Drag a guest onto a numbered chair. Anyone can sit beside anyone in this first question.
Waiting to be seated · 6
0 of 6 guests seated. Drag a guest onto a chair.
Drag people between chairs to swap them. Drop outside the chairs to cancel. You can also select a person, then a chair, using clicks or Tab and Enter. A waiting guest replaces whoever is in that chair.
60 possible circular seatings · 6 neighboring pairs to check
Turning the table or reversing the whole circle counts as the same seating. Try adding guests.These examples have a solution. Watch example shows one search by trying orders one by one, not the fastest known method.
What the names mean
Finding an answer and checking one someone gives me are different tasks. These names describe how the work grows as the problem gets bigger.
P
Polynomial timeWe can solve it efficiently.
Are there enough chairs for everyone? Count the guests and chairs.
The precise version
P contains questions with a yes or no answer that we can solve in polynomial time.
NP
Nondeterministic polynomial timeWe can check a proposed yes answer efficiently.
Someone hands me a seating order. I check that every guest appears once and every neighboring pair gets along, including the last and first.
The precise version
The evidence for a yes answer is called a certificate. For problems in NP, every yes answer has one of polynomial length that can be checked in polynomial time. NP does not mean “not polynomial”.
NP-complete
In NP and NP-hardEfficient to check, and as hard as every problem in NP.
Does any seating let everyone get along with both neighbors? This is the Hamiltonian cycle question.
The precise version
Every problem in NP can be translated into an NP-complete problem in polynomial time. An efficient algorithm for one would give us efficient algorithms for all of NP.
NP-hard
At least as hard as every problem in NPSolving it efficiently would let us solve every problem in NP efficiently.
Find the seating with the fewest awkward pairs. If the minimum is zero, a fully compatible circle exists.
The precise version
NP-hard problems don’t have to be in NP or have a yes or no answer. Counting awkward pairs in one seating is easy. Proving that no better seating exists is a different task.
How they fit together
Everything we can solve efficiently is also efficient to check.
Their yes answers are efficient to check, and solving them efficiently would let us solve every problem in NP efficiently.
The open question is whether P = NP. Does being able to check a yes answer efficiently always mean we can solve the problem efficiently too?
Adding a guest doesn't turn a P problem into an NP-hard one. The labels describe the general question we're trying to answer.
What does “efficient” mean here?
Polynomial time means the work grows no faster than a fixed power of the input size, like n or n². That doesn't always mean fast enough to use.
Why should I care?
The same questions show up when we plan deliveries, assign jobs or try to solve a puzzle.
- Getting from one place to another is a shortest path problem. With fixed, nonnegative travel times, we have efficient algorithms for it. The question “can I get there within this time?” is in P.
- Visiting a whole list of places and returning home is different. Asking whether a tour fits within a distance limit is the traveling salesperson decision problem, which is NP-complete in general. Finding the shortest tour is NP-hard.
- A completed Sudoku is easy to check. Asking whether a grid has a completion is NP-complete when the grids can keep growing. We're talking about that general problem, not one 9x9 puzzle.
Being NP-hard doesn't mean something is impossible and we should give up. We solve plenty of these problems in practice. What we don’t know is a method guaranteed to solve every instance efficiently.
What about chess, checkers and Connect Four?
Years ago, I read a paper on a flight about always winning at Connect Four. Victor Allis’s 1988 thesis describes the result: on the standard 7x6 board, the first player can force a win with perfect play. Going first isn't enough. You still have to make the right moves against whatever the other person does.
Checkers has a different answer. In 2007, the Chinook team established that standard 8x8 English checkers ends in a draw when both sides play perfectly from the starting position. That’s what “solved” means here: we know the outcome under perfect play.
Chess has the same complication: the other person gets a turn. Showing you a sequence where I win doesn’t prove I can win against every response. So I can’t just call every difficult game NP-complete. One version of chess with growing boards is EXPTIME-complete. I’m not going to get into that here, but for this version we know there is no polynomial time algorithm. With NP-complete problems, that is still the question. Solving one fixed board game doesn't settle P vs NP.
Would P = NP actually change everything?
My first reaction, from what I remembered from class, was that proving P = NP would be something like the world ending. A lot of that comes down to security. Much of modern cryptography relies on problems being hard to reverse. A practical algorithm for NP-complete problems would undermine those assumptions, including the ones behind public key encryption and digital signatures. That would be a serious problem for keeping messages private and knowing who sent them, though it wouldn't make every form of secrecy impossible.
But there is a positive side as well. The same ability could help us find better delivery routes and production schedules. We could also search efficiently for formal mathematical proofs up to a specified length, in systems where checking a proof is efficient. That doesn't mean a computer could answer every question, but it would still be an enormous change.
The catch is that polynomial time doesn't necessarily mean fast enough to use. An algorithm whose work grows like the input size raised to the hundredth power would technically qualify and still be hopeless in practice.
So I don’t think “the world ends” is quite right. Proving P = NP would be a huge result, but what changes in practice depends on the algorithm we can actually run. The proof alone wouldn't mean every password is exposed tomorrow.
Sources
- OpenAI’s Navier-Stokes claim prompted the return to the Millennium Prize Problems.
- MIT’s complexity notes explain the classes, reductions and example problems.
- Cook’s official P vs NP description gives the formal definitions and explains why polynomial time does not always mean practical speed.
- Fortnow’s overview of P vs NP covers practical approaches to hard problems and what P = NP could change.
- Allis’s Connect Four thesis establishes the first player’s win on the standard board with perfect play.
- Schaeffer’s account of solving checkers describes Chinook and the perfect play draw.
- Fraenkel and Lichtenstein’s chess result establishes the complexity of a version with growing boards.
- Fortnow on cryptography if P = NP explains what changes for secrecy and what survives.