LearnViz CompSci
Home / Learn / Theory & Discrete Math / Class P

Advanced Topic 35 of 51 Theory & Discrete Math

Class P

Problems solvable in polynomial time.

How it works

Class P contains decision problems solvable by a deterministic algorithm in time polynomial in the input size, such as sorting, shortest paths, matching, linear programming and primality testing, which is in P by the AKS algorithm. P is considered the class of efficiently solvable problems, because polynomial functions are closed under composition and tolerate changes between reasonable computational models, which is the basis of the Cobham-Edmonds thesis.

Step-by-step walkthrough

  1. P holds problems solvable in time n to some constant power.
  2. Sorting, shortest paths and primality are in P.
  3. Doubling the input does not make the time explode.
  4. P is the formal idea of efficient.

Where it is used

Choosing P-time algorithms is the goal in engineering whenever possible, and many core library functions belong here.

Common pitfall

A polynomial algorithm with a large exponent or constant can be impractical, while some exponential algorithms work well in practice for typical instances. Input size matters: an algorithm polynomial in the numeric value, such as unary knapsack, is pseudo-polynomial and not in P by the strict definition. Measure complexity in terms of the number of bits of the input. Use better algorithms before concluding a problem is hard.

Where it fits in the course

Class P is topic 35 of 51 in Theory & Discrete Math, rated Advanced. It follows Complexity Classes. The next topic is Class NP.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Theory & Discrete Math quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Class P?
Problems solvable in polynomial time. It belongs to Theory & Discrete Math and is an advanced-level topic.
Where do people use Class P?
Choosing P-time algorithms is the goal in engineering whenever possible, and many core library functions belong here.
What is the most common mistake with Class P?
A polynomial algorithm with a large exponent or constant can be impractical, while some exponential algorithms work well in practice for typical instances.
What should I learn before this topic?
Start with Complexity Classes, the topic just before it in Theory & Discrete Math.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Theory & Discrete Math quiz.
Is Class P hard to learn?
It is an Advanced topic. Expect to read the explanation more than once and to connect it with earlier topics. Working through a small example by hand helps most.
How long does it take to learn Class P?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Class P?
Complexity Classes, Class NP, Rice's Theorem are closely connected. The full list is in the related topics section of this page.
What should I study after Class P?
Continue with Class NP, the next topic in Theory & Discrete Math.

Related topics