Introduction to Time Complexity – What Are P Problems?

中文 | English

Basic Concepts in Computational Complexity

Before we dive into NP, NP-completeness, and polynomial reductions, we first need a shared language:

What is “algorithmic complexity”? What is “polynomial time”? Why are some algorithms fast but not poly-time?

We begin with three foundational complexity notions:

These concepts will appear repeatedly later.

Note
In later chapters, “polynomial time” may be abbreviated as poly-time, pseudo-polynomial as pseudo-poly-time, and weakly polynomial as weakly-poly-time.
These abbreviations are only for convenience and are not formal terminology.


Why do we emphasize poly-time?

In theoretical CS, poly-time is universally considered the threshold of efficient computation.

Because:

  1. The growth of polynomial-time algorithms (e.g., n, nlogn, n2, n3) is controlled.

  2. Changing computers, languages, and constant factors will not change its complexity class.

  3. Poly-time problems are scalable in real engineering.

Examples:

Time ComplexityPractical?Notes
O(n)very fast, linear time
O(nlogn)sorting-level fast
O(n2)acceptable
O(n7)still poly-time
O(2n)exponential blow-up
O(n)catastrophic

Thus, P problems (Polynomial-Time Problems) refer to problems solvable within practical running time.


P Problems

A problem belongs to P if there exists an algorithm whose running time is:

O(nk)

for some constant k.

Important
Note: the problem is in P, not the algorithm.
A problem is in P because it has some poly-time algorithm.

Classic poly-time algorithm examples

1. Dijkstra Shortest Path (Non-negative weights)


2. Maximum Flow

AlgorithmTimeType
Ford–FulkersonO(Cm)pseudo-polynomial
Capacity ScalingO(m2logC)weakly polynomial
Edmonds–KarpO(nm2)strongly polynomial
Orlin + KRT (improved)O(nm)strongly polynomial
Modern Approximation MethodsO(mlogn+m4/3)almost linear

Thus, Max Flow is also a P problem.


3. Minimum Spanning Tree (MST)

Hence MST is also a P problem.

These algorithms form the foundation of tractable computation.


Pseudo-Polynomial Time

One-sentence definition:

A pseudo-polynomial algorithm depends on the numerical value V of the input, not its bit-length logV.

The best example comes from dynamic programming.


Classic Example: 0/1 Knapsack DP

(570 course notes: DP Part 1)
(Carl’s tutorial: 01 Knapsack)

DP complexity:

O(nW)

Where:


Why is it not polynomial?

Because W=109 only needs 30 bits to represent—but the DP must run one billion steps.

Thus it is not poly-time.


A more intuitive explanation

You asked:

Different Paths DP is poly-time, but Knapsack DP is not. Why?

My explanation:

This disconnect between “input length” and “DP table size” makes it pseudo-poly.


Example table

Wbit-lengthDP TimeFeasible?
100010 bitsO(n1000)OK
10930 bitsO(n109)Not OK
2100100 bitsO(n2100)Impossible

Pseudo-poly algorithms frequently appear in NP-hard optimization:

We'll revisit this when discussing NP-hardness.


Weakly Polynomial Time

A weakly polynomial algorithm lies between true polynomial and pseudo-polynomial.

One-sentence definition:

Weakly polynomial time = polynomial in n and bit-length logV, but not in V itself.

Thus:


Classic example: Linear Programming (LP)

LP solvers (ellipsoid / interior-point) run in: poly(n,B)

Where:

This is truly polynomial-time and far better than pseudo-poly.


Strongly Polynomial Time

Definition:

poly(n)

Only depends on structural input size.

Examples:

Strongly poly-time algorithms are the most robust.


Final Comparison Table

TypeDepends OnExampleIn P?
Strongly Polynomialpoly(n)MST, Matching✔ Yes
Weakly Polynomialpoly(nlogV)Linear Programming✔ Yes
Pseudo-Polynomialpoly(nV)Knapsack DP✘ No (unless numbers are small)

Tip
Pseudo-polynomial algorithms may look fast, but because their dependence is on V rather than logV, they do not qualify as poly-time in the formal sense.