Skip to content
DevMeme
2944 of 7590
CS Fundamentals Post #3251 · source on Telegram

Big O Notation Surprise: From Linear to Logarithmic

Description

A surreal, deep-fried multi-panel meme that jokes about algorithmic complexity. In the first panel, a distorted frog asks, 'MOM CAN YOU GIVE ME LOOP'. The second panel shows a woman with glasses asking, 'FOR O(N)?'. In the third panel, the frog replies, 'YEES'. The fourth panel subverts the expectation, showing another frog with the text, 'ACTUALLY USES IT FOR O(LOG(N)) LIKE A BOSS'. The final, bottom panel shows a stretched frog next to a block of complex mathematical equations with the caption 'COMPLEXITY TIME'. The humor stems from the subversion of expectations in a technical context. A standard loop is often associated with linear O(n) time complexity. The developer (represented by the frog) cleverly implements a much more efficient logarithmic O(log n) algorithm, a move that is considered a mark of a skilled programmer. The meme celebrates the satisfaction of finding an optimized solution where a simpler, less efficient one was expected

Comments

19
Anonymous ★ Top Pick The difference between a junior and a senior dev: a junior sees a loop and thinks O(n), a senior sees a loop and immediately wonders if they can get away with O(log n)
  1. Anonymous ★ Top Pick

    The difference between a junior and a senior dev: a junior sees a loop and thinks O(n), a senior sees a loop and immediately wonders if they can get away with O(log n)

  2. Anonymous

    “Nice flex turning the hot loop into O(log N)… now do the part where we stop hitting the database N times so your algorithmic virtue doesn’t stay I/O-bound.”

  3. Anonymous

    When you tell the PM it'll take O(n) time to search the database but secretly implement a B-tree index because you know they'll add 'just one more requirement' that would've made the linear scan crawl to a halt in production

  4. Anonymous

    Ah yes, the classic developer move: confidently optimizing from O(n) to O(log n) only to discover your 'elegant' solution has introduced so many edge cases, nested conditionals, and auxiliary data structures that the constant factors now dominate runtime for any dataset under 10 million records. Meanwhile, the naive O(n) implementation your junior colleague wrote runs faster in production because it fits in L1 cache. But hey, at least your code review comments about Big O notation made you look smart before the performance regression tickets started rolling in

  5. Anonymous

    Ask for O(n), ship for(i=1;i<n;i*=2); then burn O(n) minutes debating the log base in code review

  6. Anonymous

    Ask for a loop vaguely; let stakeholders assume O(n!) doom while you drop O(log n) elegance

  7. Anonymous

    Turned a "just add a loop" request into O(log n); felt like a boss - until the flame graph showed 93% spent on JSON parsing and TLS handshakes

  8. @azizhakberdiev 5y

    Can anybody explain it?

    1. @jor_ban 5y

      Algorithm optimization

    2. @dkmlv_v 5y

      https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-doesnt-1674cfa8a23c/

  9. @saidov 5y

    It was quite hard to read it

  10. @grandpa_the_kid 5y

    How could he use O(n) algorithm as O(log n)? Is that quick sort, or what?

    1. @saidov 5y

      Perhaps it is probabilistic algorithm. Simple classic one, hiring problem (or in another words finding maximum value linearly), makes use of the random distribution that turns expected average from O(n) to O(logn)

      1. Deleted Account 5y

        Woah

  11. @saidov 5y

    You see, if the probability distribution of values are uniform, then with first pick we have 1/n chance of hitting max, then 1/n-1 and so on. We notice that we have the Harmonic series, which is bounded by logn

  12. @saidov 5y

    So, if you “randomly” permute the array before feeding into such algorithm, you can turn linear expected average to logarithmic

    1. Deleted Account 5y

      Permuting is O(n) :P

  13. Deleted Account 5y

    You need to pick random offsets each iteration

  14. Deleted Account 5y

    And presumably keep a hashmap of which ones are visited already making complexity even higher

Use J and K for navigation