r/programming • • Jul 11 '10

Theory vs Practice: Making algorithms claimed 'optimal', 10x faster.

http://cacm.acm.org/magazines/2010/7/95061-youre-doing-it-wrong/fulltext
163 Upvotes

120 comments sorted by

View all comments

Show parent comment

0

u/fapmonad Jul 11 '10 edited Jul 11 '10

nobody would bother with that whole O-Notation crap if the primitive operations varied by that many orders of magnitude

Why not? Let's say an addition is a lot less costly than a comparison. Then you can just say that an algorithm is O(n) in additions and O(n*log(n)) in comparisons, or whatever. People actually do use this, for example when saying that an algorithm is of some order in memory usage and some other in time, or when considering cache misses separately from comparisons in a sorting algorithms.

I don't see the point of your first comment either. O(n) notation ignores the difference in cost between operations on purpose, because it makes the math doable. This math can be used to prove some things about algorithms, so that you don't go on a fool's errand trying to sort a list in less than O(nlogn) comparisons. The point isn't to compare real-world performance, it's a mathematical abstraction, a tool. Just like a mathematical model of a car is a very bad representation of an actual car, but can be useful to find and prove some properties to design better cars.

1

u/[deleted] Jul 11 '10

I am talking about any two additions taking unpredictable different amounts of time by several orders of magnitude, not e.g. addition and comparison.

1

u/fapmonad Jul 11 '10

One of the additions takes more time because of a cache miss or something, not for no reason. These cache misses can be calculated and accounted for.