# How to compare computational complexity of algorithms

I have three different algorithms for achieving a target. Algorithm 1 takes $O(Mn)$ - $M$ is constsnt and n is variable,Algorithm 2 takes $O(min(p^3,n^3))$ - both $p$ and $n$ is variable and Algorithm 3 takes $O(nk+nd)$ - $k$ constant, $n$ and $d$ is variable. Is it possible to compare these algorithms? Which algorithm is fast and how much fast than other two algorithms?

• Compare w.r.t. what? What is the definition of "fast" you want to use? – Raphael Jun 13 '17 at 17:34

## 1 Answer

Since you have three different variable it is not easy to compare their running times. For example if $d = 1/n$ then $nd = 1$. But if $d = n$ then $nd$ is $n^2$. If $d$ and $n$ are unrelated to each other asymptotically or functionally I think you may not compare them. Analogously for $p$.

Update: If $M,p,k$ and $d$ are constant then we have Alg1 is $O(n)$, Alg2 is $O(min(p^3, n^3)) = O(p^3) = O(1)$, and Alg3 is $O(n)$.

• Thank you..But what if M,p,k and d is constant – user6745741 Jun 13 '17 at 14:17
• Then Alg1 and Alg3 have equal running times and Alg2 smaler running time in terms of big O notation of course. Linear times and const. – fade2black Jun 13 '17 at 14:20