Skip to content
Home ยป Definition of class NP, P, NP-hard and NP-complete problems

Definition of class NP, P, NP-hard and NP-complete problems


๐Ÿ“˜ Complexity Classes: P, NP, NP-Hard, NP-Complete

1๏ธโƒฃ Introduction

In computational complexity theory, problems are classified based on how efficiently they can be solved.

The most important classes are:

  • P (Polynomial time)
  • NP (Non-deterministic Polynomial time)
  • NP-Hard
  • NP-Complete

These classes help us understand:

  • Which problems are easy
  • Which are hard
  • Which are unsolvable efficiently

๐Ÿ“— 2๏ธโƒฃ Class P (Polynomial Time)

๐Ÿ”น Definition

Class P consists of all problems that can be solved in polynomial time by a deterministic algorithm.

[
O(n),; O(n^2),; O(n^3),; O(n \log n)
]


๐Ÿ”น Characteristics

โœ” Efficient and tractable
โœ” Solvable in reasonable time
โœ” Deterministic algorithms used


๐Ÿ”น Examples

  • Linear Search
  • Binary Search
  • Merge Sort
  • Shortest Path (Dijkstra)

๐Ÿ“˜ 3๏ธโƒฃ Class NP (Non-deterministic Polynomial Time)

๐Ÿ”น Definition

Class NP consists of problems for which a given solution can be verified in polynomial time.

It may be difficult to find the solution, but easy to verify it.


๐Ÿ”น Characteristics

โœ” Solution verification is fast
โœ” Solution finding may be slow
โœ” Uses non-deterministic model


๐Ÿ”น Examples

  • Traveling Salesperson (decision version)
  • Subset Sum
  • Hamiltonian Cycle

๐Ÿ“™ 4๏ธโƒฃ NP-Hard Problems

๐Ÿ”น Definition

A problem is NP-Hard if:

It is at least as hard as the hardest problems in NP.

  • Not necessarily in NP
  • May not be decision problems
  • May not have polynomial-time verification

๐Ÿ”น Characteristics

โœ” Very difficult problems
โœ” No known efficient solution
โœ” May be optimization problems


๐Ÿ”น Examples

  • Traveling Salesperson (optimization version)
  • Halting Problem
  • Scheduling problems

๐Ÿ“• 5๏ธโƒฃ NP-Complete Problems

๐Ÿ”น Definition

A problem is NP-Complete if:

  1. It belongs to NP
  2. It is NP-Hard

๐Ÿ”น Meaning

  • Hardest problems in NP
  • If one NP-Complete problem is solved in polynomial time โ†’ all NP problems can be solved in polynomial time

๐Ÿ”น Examples

  • SAT (Boolean Satisfiability Problem)
  • Subset Sum
  • Clique Problem
  • Vertex Cover
  • Hamiltonian Cycle

๐Ÿ“Š 6๏ธโƒฃ Relationship Between Classes

P โІ NP
NP-Complete โІ NP
NP-Hard โЇ NP-Complete

๐Ÿ‘‰ Key idea:

  • All P problems are in NP
  • NP-Complete problems are hardest in NP
  • NP-Hard includes even harder problems

๐Ÿ“Œ 7๏ธโƒฃ P vs NP Problem

  • Biggest open problem in computer science
  • Question:

Is P = NP?

โœ” If YES:

  • All NP problems become easy

โœ” If NO:

  • Some problems are inherently hard

๐Ÿ“Š 8๏ธโƒฃ Summary Table

ClassMeaningSolvable?Verifiable?
PEasy problemsโœ” Yesโœ” Yes
NPVerifiable problemsโ“ Unknownโœ” Yes
NP-HardVery hard problemsโ“ UnknownโŒ Not always
NP-CompleteHardest in NPโ“ Unknownโœ” Yes

๐Ÿ”Ÿ Key Differences

FeaturePNPNP-HardNP-Complete
Solution timePolynomialUnknownUnknownUnknown
VerificationEasyEasyNot alwaysEasy
TypeEasyMediumHardVery Hard

๐Ÿ”š Conclusion

The classification of problems into P, NP, NP-Hard, and NP-Complete helps us understand the limits of computation.

NP-Complete problems are the most critical, as solving one efficiently would solve all NP problems efficiently.


๐Ÿ“Œ Exam Tip

๐Ÿ‘‰ Always include:

  • Definitions
  • Examples
  • Relationship diagram
  • P vs NP statement