Is the combination of two polynomial time algrorithms polynomial time?

175 Views Asked by At

I am very new to time complexities and I am trying to understand whether this statement is true, and how one would prove it if so. For example, if you had a polynomial time algorithm to determine if a graph is connected, and a polynomial time algorithm that takes a connected graph as an input and outputs some value relating to the graph (maybe the chromatic polynomial just for an example), then is the algorithm that takes any graph as input and outputs the chromatic polynomial (if the graph is connected) polynomial time?

3

There are 3 best solutions below

0
On BEST ANSWER

The running time of any number of algorithms running sequentially is the sum of the running times of its constituents. Asymptotics therefore naturally carry over from the one-algorithm case: the asymptotics of the sequence are the same as that of its slowest constituent. In particular, if all the algorithms are poly-time, so is their combination.

0
On

Yes, it is. If the algorithms have complexities $O(n^k)$ and $O(n^l)$ then running them in sequence as described has complextity $O(n^{\max\{k, l\}})$ using the definition of $O$.

0
On

If $f(x)$ is a polynomial and $g(x)$ is a polynomial, the composition $f(g(x))$ is also a polynomial. Therefore, composing a polynomial time routine as a step of another polynomial time routine yields a polynomial time complexity for the overall routine.