3

From wikipedia

In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is a polynomial in the length of the input (the number of bits required to represent it) and the numeric value of the input (the largest integer present in the input). In general, the numeric value of the input is exponential in the input length, which is why a pseudo-polynomial time algorithm does not necessarily run in polynomial time with respect to the input length.

From this SO post

An algorithm runs in pseudo-polynomial time if the runtime is some polynomial in the numeric value of the input, rather than in the number of bits required to represent it.

I have some questions about the wiki definition. To my knowledge, the definition provided by the SO post makes more sense. Shouldn't the wiki say pseudo-polynomial time is if the running time is
1) exponential (or something greater than polynomial) in the length of the input, and
2) polynomial in the numeric value of the input (largest number of input)
??

Assuming you have answered the question of definition above,

I am having trouble analyzing the running time of Counting Sort which is $O(N + K)$ with respect to $N, K$, the numeric values of the input.

Assuming we do not have the $k = \Theta(N)$ simplifying condition, the length of the input is $x = \Theta(N\log(k))$ bits.

The Wiki says "In general, the numeric value of the input is exponential in the input length". But $k = 2^{\Theta(\frac{x}{N})}$. With N potentially bringing down the magnitude of the exponent, I don't really see how $k$ is exponential in $x$.

In addition, the SO post I referenced claims counting sort runtime is exponential with respect to the length of the input, $x = \Theta(N\log(k))$ bits. How can $O(N + k)$ be transformed into an expression exponential in $n$ to demonstrate the claim? I got it down to $O(\frac{x}{\log(x)} + k)$ but got stuck there.

If I just think the length of the input is $\Theta(\log k)$ then I can see why the run-time is exponential but this doesn't seem to be consistent with how $x$ should be defined.

namesake22
  • 221
  • 1
  • 9

1 Answers1

2

Let us denote the input's length by $n$, and lets remember that $n=\Theta\left(N\log K\right)$. You won't be able to write the exact running time of counting sort as an expression of the form $2^{\Omega(n)}$, as this would mean that for large enough inputs, the running time is always exponential. However, in this case, if $K$ is not too large compared to $N$, then the running time is actually linear, this means that there exists an infinite series of inputs with increasing size on which the running time is not exponential.

With this is mind, recall that what you seek is the worst case complexity of your algorithm, i.e. you want to find a certain time bound that holds for all inputs of large enough size. This means that to lower bound the complexity, it suffices to find one series of inputs with increasing size on which the running time is exponential. This allows you to focus on inputs where $K=2^N$, in this case the input size is $n=\Theta\left(\log^2 K\right)$, and the running time is $O(K)=O\left(2^{\sqrt{n}}\right)$, which is definitely exponential.

In general, a pseudopolynomial time algorithm is an algorithm which runs in polynomial time in the numeric value of the input (which means it is not necessarily polynomial in the input's length). Wiki's definition is no different, except it adds the restriction that the running time is polynomial in both the numeric value and the input size, i.e. if the input size is $n$, and its associated numeric value is $v$, we want a time bound of the form $p(n,v)$ for some polynomial $p$. This excludes for example a $2^N+K$ time algorithm for sorting $N$ numbers in the range $[1,K]$, although this is polynomial in $K$.

Ariel
  • 13,614
  • 1
  • 22
  • 39