Is this solvable in polynomial or pseudo-polynomial time?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In computational complexity theory, one of the central quests is determining whether specific problems can be solved in polynomial time, and if not, whether they can be approached in pseudo-polynomial time. Understanding these terms and their implications is crucial for computer scientists and mathematically inclined individuals. This article delves into the technical nuances of both polynomial and pseudo-polynomial time, exploring their importance and providing insightful examples.
Defining Polynomial and Pseudo-Polynomial Time
Polynomial Time
A problem is said to be solvable in polynomial time if there exists an algorithm that can solve instances of the problem in time that is a polynomial function of the size of the input. More formally, if the size of the input is , an algorithm runs in polynomial time if its time complexity can be expressed as , where is a constant.
Example:
- Searching Algorithms: Linear search operates in time, where is the number of elements in the list.
- Sorting Algorithms: Merge sort operates in time, which, although not strictly polynomial, is often considered efficient in comparison to other complexities like exponential.
Pseudo-Polynomial Time
A problem is solvable in pseudo-polynomial time if the running time of an algorithm is polynomial in the numerical value of the input (as opposed to the input size). In pseudo-polynomial algorithms, the complexity depends on the numeric value of the input rather than just its length.
Example:
- Knapsack Problem: The dynamic programming solution runs in time, where is the number of items, and is the maximum weight capacity of the knapsack. As grows, the running time becomes impractical even if the algorithm is polynomial in .
Key Concepts
| Concept | Definition | Examples |
| Polynomial Time | Algorithm's runtime grows polynomially with input size. | Linear search (), Merge Sort () |
| Pseudo-Polynomial Time | Algorithm's runtime grows polynomially with numerical value of input. | Knapsack Problem () when is the weight limit and the number of items. |
| NP-Complete | Problems that are as hard as the hardest problems in NP, and can be verified in polynomial time if a solution is known. | Subset Sum Problem |
| NP-Hard | Problems that are at least as hard as the hardest problems in NP, not guaranteed to be solvable in polynomial time. | Travelling Salesman Problem |
NP-Complete and NP-Hard Problems
When discussing polynomial-time algorithms, NP-complete and NP-hard problems frequently enter the conversation. These problems often highlight the upper bounds of what is considered feasibly computable within polynomial constraints.
NP-Complete Problems
NP-complete problems are those for which no known polynomial-time algorithm exists, yet a solution can be verified quickly if provided. An example is the Subset Sum Problem, which asks if a subset of numbers in a set can be summed to equal a particular value.
NP-Hard Problems
NP-hard problems are even more challenging as they may not even reside within the NP class, meaning a solution might not be verifiable in polynomial time. The Travelling Salesman Problem belongs to this category, seeking the shortest possible route that visits each city exactly once and returns to the origin city.
Exploring Complexity Classes
P and NP
These are fundamental complexity classes. All problems in P are solvable in polynomial time, whereas problems in NP can be verified in polynomial time. The famous open question in computer science is whether P equals NP, i.e., whether every problem that can be verified quickly can also be solved quickly.
Pseudo-Polynomial vs. Polynomial Time
The distinction between pseudo-polynomial and polynomial time is subtle but significant:
- Data Size Dependency: Polynomial algorithms depend only on the number of bits, while pseudo-polynomial algorithms also depend on instance numerical values.
- Scalability: Pseudo-polynomial algorithms may become unwieldy as numeric input values grow large, even if the input size (in bits) remains modest.
Conclusion
The investigation into whether a problem is solvable in polynomial time or pseudo-polynomial time is not merely academic; it has practical implications influencing computational efficiency and resource allocation. While polynomial-time solutions are undeniably preferable, pseudo-polynomial approaches provide valuable methodologies, especially in hashing fundamental NP-complete and NP-hard challenges. Exploring these concepts equips practitioners and theorists alike to better navigate the nuanced landscape of computational complexity.
Related reading
- Is this technically an O1 algorithm for Hello World?
- Is this technically an O1 algorithm for Hello World?
- Is this variant of the subset sum problem easier to solve?
- Is timsort general-purpose or Python-specific?
- Is trigonometry computationally expensive?
- Is using batch size as 'powers of 2' faster on tensorflow?
- Is Topological Sorting trying to sort vertices or edges?
- Is two pointer problem same as sliding window

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.