0
$\begingroup$

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?

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

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)$.

$\endgroup$
  • $\begingroup$ Thank you..But what if M,p,k and d is constant $\endgroup$ – user6745741 Jun 13 '17 at 14:17
  • $\begingroup$ 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. $\endgroup$ – fade2black Jun 13 '17 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.