Key differences between P, NP, NP-complete, and NP-hard

Rasel MahmudRasel Mahmud
2 min read
CategoryPNPNP-completeNP-hard
DefinitionProblems that can be solved in polynomial time by a deterministic algorithm.Problems whose solutions can be verified in polynomial time by a deterministic algorithm.Problems that are both in NP and as hard as the hardest problems in NP (NP-hard and in NP).Problems as hard as NP-complete problems but not necessarily in NP (not required to be verifiable in polynomial time).
Key CharacteristicsEfficiently solvable in polynomial time.Solution verification is efficient (polynomial time).If any NP-complete problem is solved in polynomial time, all NP problems can be solved in polynomial time.May not even be solvable or verifiable in polynomial time.
Verifiable and solvable in polynomial time.Includes all problems in P.Requires verification and reduction properties.Includes optimization problems and undecidable problems.
A subset of NP problems.May not be efficiently solvable.Solving one in polynomial time solves all NP problems in polynomial time.Not necessarily solvable or verifiable in polynomial time.
ExamplesSorting (e.g., Merge Sort), SearchingBoolean Satisfiability (SAT), Graph Coloring3-SAT, Traveling Salesman (decision version)Halting Problem, Bin Packing Problem

Key Differences:

  1. Problem Solving:

    • P: Problems can be both solved and verified in polynomial time.

    • NP: Problems may not be solved in polynomial time but can be verified in polynomial time.

    • NP-complete: Problems are the hardest in NP and are solvable if any NP problem is solved in polynomial time.

    • NP-hard: Problems are as hard as NP-complete but not necessarily in NP (i.e., they might not even have a verifiable solution in polynomial time).

  2. Inclusion:

    • P: Subset of NP.

    • NP-complete: Subset of NP-hard.

    • NP-hard: Not necessarily a subset of NP.

  3. Implication:

    • Solving any NP-complete problem in polynomial time implies P=NP.

    • Solving an NP-hard problem does not necessarily affect P=NP, as NP-hard problems might not be verifiable.

Math Relationship:

  • P ⊆ NP.

  • NP-complete ⊆ NP.

  • NP-complete ⊆ NP-hard.

  • NP-hard includes problems that might not belong to NP.

0
Subscribe to my newsletter

Read articles from Rasel Mahmud directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rasel Mahmud
Rasel Mahmud

I am currently pursuing a Master’s in Software Engineering at USTC, with a strong focus on Machine Learning for AI-driven solutions. My journey has been diverse, in addition to my academic journey. In 2020, I started to learn graphic design➡️video editing➡️digital marketing and later dived into➡️Full-Stack JavaScript web development. Each experience has strengthened my ability to analyze, optimize, and create impactful solutions. From 2023, I'm training myself in machine learning end-to-end project approach to solving real-world challenges.