Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Strictly speaking, Big-O <em>doesn't</em> tell you about the growth for numbers you actually use.</p> <p>Big-O notation is about what happens in the limit as the size of the problem (<code>n</code>) tends to infinity. Specific small numbers like 4096 and 8192 are irrelevant to big-O classification. Furthermore, big-O is an <em>upper limit</em>. Bubble sort is O(n^2). It is also O(n^3), and O(n^27), and O(2^n), because all of those functions also provide upper bounds on its running time in the limit. Very loose upper bounds, but bounds nonetheless.</p> <p><em>In practice</em>, many or most algorithms that you'll use, can be observed for realistic values of <code>n</code>, to follow a trend corresponding to their "best" big-O complexity. And that's what you're seeing here - doubling the size quadruples the time, because time is approximately proportional to n^2. Because time is proportional to n^2, the algorithm is O(n^2). The reverse implication does not necessarily hold.</p> <p>People commonly say "bubble sort is O(n^2)", and they mean, "the time taken to bubble sort is proportional to the square of the input size, ignoring a small percentage of special cases which are much faster (already-sorted data in the case of bubble sort)". Both statements are true, but the latter is not what the former actually means, so occasionally it's confusing. Several answers here say the same thing, and they're wrong too as far as the mathematical definition of big-O is concerned. But the incorrect usage is so common that it can't be ignored, presumably because people are informally introduced to big-O classifications of algorithms without ever being taught a formal definition.</p> <p>So, when someone tells you that an algorithm is O(n^2), there's a fairly high probability that what they're <em>trying</em> to tell you is that its worst case is &Theta;(n^2), and if so they might well be further trying to tell you that this trend is observable for the kinds of <code>n</code> you care about. Given this abuse of notation, that's why "O(n^2) algorithms" all become less efficient as you increase <code>n</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload