Reasoning on Efficiency (2) - Computer Science Stack Exchange most recent 30 from cs.stackexchange.com 2019-08-22T08:24:30Z https://cs.stackexchange.com/feeds/question/67080 http://www.creativecommons.org/licenses/by-sa/3.0/rdf https://cs.stackexchange.com/q/67080 1 Reasoning on Efficiency (2) Tobi Alafin https://cs.stackexchange.com/users/62509 2016-12-07T23:03:44Z 2016-12-08T08:44:12Z <p>Two algorithms to solve a particular problem can have theur efficiency compared using the $O$ and $o$ notation. However, this is very crude method, and tells us no information on how more effective one is than the other.</p> <p>Is there a yard stick that can be applied to <em>ALL</em> algorithms, with <em>ALL</em> time complexities, that can be used to evaluate the efficiency of two algorithms?</p> <p>I actually developed a method for this, but it applies only to polynomial algorithms. </p> <p>MY METHOD. </p> <blockquote> <p>Suppose we want to compare two algorithms for accomplishing a task $f_i(n), g_i(n)$. $f_i(n) = o\left(g_i(n)\right)$<br> A simple way to compare $f_i$ and $g_i$, is to find their ratio $r_i(n)$<br> $$r_i(n) = \frac{g_i(n)}{f_i(n))}$$<br> Express $r_i(n)$ as a polynomial of ,$n$.<br> $$r_i(n) = n^{k}, \{k: k \in \Bbb R\}$$<br> $$m = \lceil{k}\rceil$$ </p> <p>$R_i(n) = m^{th}$ derivative of $r_i(n)$.<br> It follows that $R(n)$ is a constant.</p> </blockquote> <p>My method works nicely for polynomial algorithms, but is completely useless for other time complexities. Is there a more effective yardstick? One that applies to all complexities?</p> https://cs.stackexchange.com/questions/67080/reasoning-on-efficiency-2/67083#67083 5 Answer by D.W. for Reasoning on Efficiency (2) D.W. https://cs.stackexchange.com/users/755 2016-12-07T23:48:20Z 2016-12-07T23:48:20Z <p>The concepts of asymptotic running time analysis and Landau notation <em>already</em> provide a way to compare the asymptotic running time of two algorithms, as long as (a) you are happy to ignore constant factors, (b) only care about asymptotics (limiting behavior as problem size gets large), and (c) you want to evaluate them according to their worst-case running time. It sounds like you are happy with (a), (b), and (c), so you should be happy with existing tools. They <em>do</em> tell you how much more efficient one algorithm is than the other. You just might not have appreciated yet how to fully use these mathematical tools and concepts, which is understandable.</p> <p>In particular, if we can express the running time of algorithm A as $\Theta(f(n))$ and the running time of algorithm B as $\Theta(g(n))$, we already know how to compare them. We know that the ratio of their running time is $\Theta(f(n)/g(n))$. In particular:</p> <ul> <li><p>If $f(n)/g(n) = \Theta(1)$, we know that their asymptotic worst-case running times are equivalent.</p></li> <li><p>If $f(n)/g(n) = o(1)$ (i.e., $f(n) = o(g(n))$), we know that A is asymptotically faster, and we can measure asymptotically how much faster: it is faster by a factor of $\Theta(f(n)/g(n))$.</p></li> <li><p>If $f(n)/g(n) = \Omega(1)$ (i.e., $f(n) = \Omega(g(n))$, or equivalently, $g(n) = o(f(n))$), we know that B is asymptotically faster, and we can measure asymptotically how much faster: it is faster by a factor of $\Theta(g(n)/f(n))$.</p></li> </ul> <p>You might want to read <a href="https://cs.stackexchange.com/q/192/755">How to come up with the runtime of algorithms?</a>, <a href="https://cs.stackexchange.com/q/57/755">How does one know which notation of time complexity analysis to use?</a>, <a href="https://cs.stackexchange.com/q/824/755">Sorting functions by asymptotic growth</a>, <a href="https://cs.stackexchange.com/q/23068/755">How do O and Ω relate to worst and best case?</a>, and <a href="https://cs.stackexchange.com/q/9957/755">Justification for neglecting constants in Big O</a>. That will give you some essential background to help you understand how these concepts fit in.</p> <p>(I'm simplifying a bit, and casting this at the level that it sounds like you're ready to absorb. Once you understand the basics, read <a href="https://cs.stackexchange.com/q/1780/755">Are the functions always asymptotically comparable?</a> if you want to read some more precise statements -- but beware that right now this might just cause more confusion than it's worth.)</p> https://cs.stackexchange.com/questions/67080/reasoning-on-efficiency-2/67084#67084 2 Answer by David Richerby for Reasoning on Efficiency (2) David Richerby https://cs.stackexchange.com/users/9550 2016-12-08T00:54:01Z 2016-12-08T08:44:12Z <p>All you're doing is comparing two functions by taking their ratio. The only reason you think this is restricted to polynomials is that you want to express the ratio as a polynomial. If you don't restrict the ratio to be a polynomial, you can relate arbitrary functions. (Actually, it's not restricted to polynomials since, e.g., if $f(n)=n^22^n$ and $g(n)=n2^n$, $f/g$ is still a polynomial.)</p> <p>But, in general, the ratio of two polynomials <em>isn't</em> a polynomial; rather, it's a so-called rational function. For example, $(x^2+1)/x = x+\tfrac1x$, which isn't of the form $x^k$ for any real&nbsp;$k$, and which has no constant derivatives.</p>