What are NP, NP-Complete, and NP-Hard problems?

Answer

Complexity classes for decision problems: P (Polynomial time): problems solvable in polynomial time O(n^k) by a deterministic Turing machine. Examples: sorting, shortest path, primality (AKS). NP (Nondeterministic Polynomial): problems where a proposed solution can be verified in polynomial time. Examples: Subset Sum, TSP, 3-SAT, Graph Coloring. P ⊆ NP (solving implies verifying). Whether P = NP is the most important open problem in computer science ($1M Millennium Prize). NP-Hard: every NP problem can be reduced to it in polynomial time — as hard as the hardest NP problems. NP-Hard problems may or may not be in NP. Examples: Halting problem (not in NP), TSP optimization version. NP-Complete: both NP and NP-Hard — the hardest problems in NP. If any NP-Complete problem is solvable in polynomial time, then P = NP. Examples: 3-SAT, Vertex Cover, Independent Set, Clique, Hamiltonian Path, Travelling Salesman (decision), Subset Sum, Graph Coloring (3+ colors), Knapsack. Reductions: Cook's theorem proved 3-SAT is NP-Complete; all others proved NP-Complete by polynomial-time reduction from a known NP-Complete problem. Practical handling: approximation algorithms (near-optimal), heuristics, fixed-parameter tractability, or exponential algorithms for small inputs.