Plain English explanation of Big O
stackoverflow.com
stackoverflow.com
This is a pretty huge benefit because it means every CS paper doesn't have to start with a section introducing an abstract machine. The downfall is, of course, that you lose some ability to estimate the potential real-world performance of the algorithm, and the notation itself hides differences between algorithms of the same Big O complexity.
O is a simplification of a function, but says nothing about how to construct the function. You need to have your (implicit) computational model before you can start counting critical operations, whether you describe it or not.
This is actually somewhat important, since almost everyone has agreed on a model that, among other things, considers random access, multiplication, hashing, and even explicitly O(log log n) operations to take constant time. It's one of the many reasons why people make incorrect proofs about P=?NP.
edit: If you meant that the simplification abstracts away implementation details like 3n^2+42 vs 2n^2+n, you're right, that's valuable. But I still argue that you ascribe it too much value when it comes to underspecifying your computational model.
http://discrete.gr/complexity/
And if you don't like it, you can edit it too:
"You can't compare an algorithm to do arithmetic multiplication to an algorithm that sorts a list of integers."
I rarely if ever implement just a multiplier or just a sorter. I end up implementing systems. And if everything in the system is linear or small poly but step #7 is exponential, then comparing Big O for unrelated algos is extremely valuable for me to estimate how long the overall system is going to take and where optimization effort should be placed for best improvement, etc. Don't waste time on making something linear a little faster, when I could be trying to refactor something exponential into something merely poly, somehow (assuming its even theoretically possible per some big O evaluation). Or refactor the whole system to be only poly.
It's a function which takes a list of numbers as inputs. You give it a list of two numbers. It executes four operations before terminating.
You give it a list of three numbers. It executes nine operations before terminating.
You give it a list of four numbers. It executes sixteen operations before terminating.
You see how the time required grows as n^2 with respect to the input? That's an O(n^2) algorithm, and that's why such an algorithm can be bad. A list of 1,000,000 numbers would require a trillion operations.
The way this can happen is if you write a double-for loop:
for x in input:
for y in input:
...
So, there you go. You probably won't get any plainer of an explanation without becoming oversimplified and losing meaning.An algorithm with runtime r(n) is "big O" of f(n) if the limit as n -> infinity of r(n) / f(n) <= some constant.
EDIT: See replies below.
Which definition of asymptotic notation is there besides the mathematical definition, which by definition defines it? :)
Here are the previous submissions with the most discussion:
https://news.ycombinator.com/item?id=1520552 (24 comments, 1242 days ago)
I found them by using this search:
https://www.hnsearch.com/search#request/all&q=title%3A%28pla...
Here are some other submissions:
https://news.ycombinator.com/item?id=695988 (4 comments)
https://news.ycombinator.com/item?id=2344181
https://news.ycombinator.com/item?id=3807175
https://news.ycombinator.com/item?id=3846993
https://news.ycombinator.com/item?id=5164236
https://news.ycombinator.com/item?id=5636683
https://news.ycombinator.com/item?id=5778469
This submission of the same item has some discussion, but mostly of the fact that this item is submitted so often, whether it's a problem, and whether we should do something about it, possibly to make HN a better source of curated discussion:
https://news.ycombinator.com/item?id=5785523 (24 comments)
The answer seems to be "No".
Additionally, you might be interested in reading these:
https://news.ycombinator.com/item?id=4655061 : Big-O Misconceptions
https://news.ycombinator.com/item?id=5770232 : What does O(log n) mean, exactly?
A plain English explanation of Big O notation shouldn't take more than a few sentences. It's not that complicated, especially if you don't get into nitty gritty.
It's unnecessarily different than the normal definition of "complexity." When you say "complex" in normal conversation, you mean "complicated" or "hard to understand." You would never say "the time complexity of getting to the airport is 30 minutes."
It also begs the question. Wrapping your head around the idea of asymptotic complexity is the hard part of understanding big O. Defining big O in terms of complexity doesn't help if you don't understand the concept of asymptotic complexity yet.
I think the best way to explain this, by far, is with a graph.
[1] http://en.wikipedia.org/wiki/Big_O_notation#Orders_of_common...
Now suppose we have an input and the output made by this program. But we don't have the program. Suppose we want to discover by brute force what the program was.
The brute-force algorithm will create every possible program up to N bits long, and run each one until either a difference in outputs is found, or it found the correct output, or too much time has passed.
How do you come up with the order-notation for this brute-force algorithm?
EDIT: I suppose if the time bound per program is a parameter "m" that you can vary, then it's actually O(m*2^n).
Without the bound, this algorithm is unlikely to work, since programs can run indefinitely.
If you modify your algorithm to only generate programs without any infinite loops, you've solved the halting problem, which is impossible.
Nonsense, there is no reason you cannot design an algorithm that uses a halting oracle. Running that algorithm may be difficult though.
You absolutely can generate only programs that terminate; for instance, throw out any that have recursion or unbounded loops, or use a non Turing complete language that is guaranteed to terminate.
That you can't solve the halting problem in general does not mean that static analysis is fruitless. The answer to "does this terminate" will be yes, no or maybe, almost always in the latter category.
The correct thing to say would be:
If you modify your algorithm to only generate programs without infinite loops, you've most likely thrown out the correct solution.
I'm not sure this is a decidable problem with just the information you gave.
Did you just make up the problem, or is that inspired from a real world situation?
http://lucatrevisan.wordpress.com/2010/03/07/on-the-necessit...
Oh, wait...
See his content here: https://news.ycombinator.com/user?id=cletus
f(n)=O(n^2) is actually NOT f(n) asymptotically grows as fast as n^2, it is f grows “no faster” than n^2.
“As fast as” is f(n)=Θ(n^2)
Edit: oh, and Big-O is not “a relative representation of the complexity of an algorithm”
honestly the language of maths too often obfuscates rather than simplifies
Finally, big-O notation describes arbitrary function growth, not just the runtime of some operation when applied to a list. It's used a lot in numerical analysis where you can show that some function can be approximated by, say, x - x^3/6 + x^5/120 + O(x^7).
one question though - do you have a source for this 'irregularities' bit? I've never seen that mentioned before at all and a Google hasn't helped. doesn't seem to fit with 'upper bound' and 'worst case'.
[edit: also still not sure how you say im confusing for theta. that's what 'the largest number of times it might' was for.]
You're right about the theta thing, my mistake.
This is wrong on so many levels, I don't even know where to begin.
Mathematical formulas and equations are the ultimate tool for simplification and abstraction, the best that humankind could come up with. Explaining mathematical concepts precisely in natural language can be extremely difficult and time-consuming. The only problem is, you have to learn that language, just like any other language. Otherwise, it's like complaining that Japanese "obfuscates" things because you can't read a sentence in Japanese.