where restricts every numerical magnitude to at most and is the binary encoding length. Here numbers are represented in base two as binary numbers; any other fixed base greater than one gives the same classification.
Pseudo-Polynomial Algorithms
Standard weakly NP-hard problems admit pseudo-polynomial algorithms: their running time is polynomial in the unary encoding length , which may be exponential in .
When every number is at most for a fixed polynomial , there are at most numbers, so
The algorithm therefore runs in polynomial time on every such restriction. Assuming P ≠ NP, this proves that the problem is not strongly NP-hard.
Some texts use “weakly NP-hard” specifically for NP-hard problems with a pseudo-polynomial algorithm. Under the broader definition above, such an algorithm is sufficient, but its existence does not follow merely from the failure of strong NP-hardness.
Hard in Binary, Tractable in Unary
If the unary encoding length is upper-bounded by a fixed polynomial in the binary encoding length , then polynomial time in is also polynomial time in .
Distinguish two kinds of magnitude in an explicitly represented input:
A structural count requires objects to be present in the input. A numerical value need not require symbols:
Changing the number encoding does not change or . It changes how much space occupies: logarithmic in binary, linear in unary.