Skip to content
HomeVideosBooksBlogs
AllTop postsTopics
Podcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    A

    Accidentally Quadratic

    accidentallyquadratic.tumblr.com · Personal blog · on HN since 2015

    Accidentally Quadratic is a Tumblr collecting real-world cases where code unexpectedly takes quadratic time, across many languages and libraries.

    Visit blogHN submissions
    ProgrammingSystems & Performance
    What HN says

    HN commenters recommend it as a dose of real-world big-O, noting it shows how abstraction hides complexity, and cite it in language arguments.

    Stats for nerds
    72HN people shared it
    30linked in comments
    873story points
    Apr 2026last shared
    2015people per year2026

    Top posts on HN

    1. 1
      Ruby `reject!`
      1 person · 306 points · first shared 2017 · 141 comments on HN
    2. 2
      Accidentally Quadratic
      45 people · 195 points · first shared 2015 · 78 comments on HN
    3. 3
      Rust Standard Hash Table Could Go Quadratic
      11 people · 165 points · first shared 2016 · 18 comments on HN
    4. 4
      Why Accidentally Quadratic?
      3 people · 94 points · first shared 2015 · 21 comments on HN
    5. 5
      Algorithmic Complexity of Left-Pad (2016)
      7 people · 93 points · first shared 2016 · 25 comments on HN
    6. 6
      Elasticsearch IndicesQuery
      1 person · 6 points · first shared 2017 · Discussion on HN
    7. 7
      Accidentally Quadratic – GHC Derived Foldable and Traversable Instances
      1 person · 5 points · first shared 2015 · Discussion on HN
    8. 8
      Accidentally Quadratic: Ruby `parser` gem
      2 people · 4 points · first shared 2016 · Discussion on HN
    9. 9
      Accidentally Quadratic – Chrome Server-Sent Event Parsing
      1 person · 2 points · first shared 2016 · Discussion on HN
    10. 10
      Vim TAGS lookup
      1 person · 1 points · first shared 2017 · Discussion on HN

    What HN people wrote when they linked it

    • jerfJun 2023

      For me, I think the problem is that normal, boring, stupid, unsophisticated, plebian imperative programming lives in a world of O(1) operations. That is to say, a "normal" line of code you type will be O(1), and then you generally start gluing those together with various things that start stacking on O(n) complexities. As things like the accidentally quadratic blog [1], in the normal programming world it is a bit humorous to even so much as accidentally stack two of those things unnecessarily on top of each other.

      Certainly, people manage to make poorly performing things even so, but at least at the base level, your primitives may be stupid, but they are generally fast.

      The logic programming world works in a default space of O(n) operations, that stack together more freely than the imperative world, and that gives easy access to O(2^n). Since this is essentially impossible, a great deal of work is done to try to get that down, but you're always intrinsically starting behind the eight-ball. It is easier to work up from O(1) operations than to write an exponential or super-exponential algorithm and then try to trim it back down to a decent complexity for a normal programmer.

      I think this is the root cause as to why logic programming is generally not something we see a lot of. It's like a wild stallion; it may be powerful but the amount of effort you pour into just keeping it under control may exceed any benefit you could get.

      It isn't useless, of course. Amazing work has…

    • deathanatosMay 2022

      > The thing about Computer Science nowadays is that the machines are stupidly fast so that a lot of the algorithm stuff is redundant.

      Accidentally quadratic is such a thing there's a blog[1], and it's regularly the source of problems of a certain blogger who debugs problems in Windows that are usually causing his "stupidly fast" hardware to run bog slow[2].

      Just this week, I hit what seems to be an accidentally-quadratic bug in macOS's tail — tail! I'm not even sure how you write an accidental O(n²) in implementing tail, but yet macOS tail takes 7 minutes to process a log file on my system that GNU tail can process in 80 milliseconds.

      Regex regularly lead to oops-O(n²) due to devs not grokking the greedy nature of the star character, and for a while last year it felt like every week some NPM package was getting a security vuln. for a DoS vuln. due to quadratic regexes.

      Understanding how B-Trees work — and more importantly, when they don't — in database queries is a perennial source of bugs in every company I've worked at where queries get written that won't hit an index, and don't get noticed until they're hitting production levels of rows. Dev confusion entails — "but the index has the columns I'm querying!" … yes, but that's not how a B-Tree works.

      And it's not just the order-notation. I've seen, numerous times, people re-discover topological sort, or worse, hack a solution onto a problem where the problem is a DAG, and the solution is topo-sort, but instead you get…

    • tomsmedingAug 2020

      Asking if the list is sorted was also the very first question that popped up in my head, because it makes the difference between a linear and a quadratic algorithm. Contrary to, for example, having the choice between an n log n algorithm and a linear algorithm, when given the choice between a quadratic and a linear algorithm, it is very rare that the right choice is the quadratic algorithm. (Semi-related: [1])

      (EDIT: after thinking about this more than two seconds, the quadratic algorithm for unsorted input can become n log n by sorting the list, though that takes linear space. This would certainly be a clarifying question.)

      The other questions would be less obvious to me, though I'd encounter them while thinking more than 2 seconds about the problem, I suppose.

      Or maybe this just outs me as an ex-amateur competitive programmer :)

      [1]: https://accidentallyquadratic.tumblr.com/

    • btillySep 2025

      Bottom up dynamic programming algorithms require some cleverness.

      All of the ones listed can be solved with a top down dynamic programing algorithm. Which just means "write recursive solution, add caching to memoize it".

      For some of these, you can get cleverer. For example the coin change problem is better solved with an A* search.

      Still, very few programmers will actually need these algorithms. The top thing we need is to recognize when we accidentally wrote a quadratic algorithm. A quick scan of https://accidentallyquadratic.tumblr.com/ shows that even good people on prominent projects make that mistake on a constant basis. So apparently being able to produce an algorithm on the test, doesn't translate to catching an algorithmic mistake in the wild.

    • strmpnkOct 2018

      This reminds me of the Accidentally Quadratic series: https://accidentallyquadratic.tumblr.com/

      These issues are quite common and seem to grow out of that initial expectation that N stays small which later turns out to not be so true for cases discovered later on. Scrolling through some of the latest entries, even Chrome itself had some accidentally quadratic complexity.

    • tom_melliorApr 2017

      Ah, blaming the language.
      See https://accidentallyquadratic.tumblr.com/ for other languages and systems (including HN's current favorite, Rust), which apparently also "[hide] away the computational complexity and [make you] wonder why the execution is so slow".

      Not saying Prolog performance can't be tricky, but it's not that easy in other languages.

    Related

    beza1e1beza1e1.tuxen.de120 people

    A collection of things that are Turing-complete by accident (2013)

    beza1e1
    Personal · last shared 2026
    Useless Factoruseless-factor.blogspot.com16 people

    Why not mmap?

    Useless Factor
    Personal · last shared 2015
    Eric Kiddrandomhacks.net65 people

    Rust lifetimes: Getting away with things that would be reckless in C++

    Eric Kidd
    Personal · last shared 2026
    Lambda Diodelambda-diode.com18 people

    Interfacing Fortran with OCaml

    Lambda Diode
    Personal · last shared 2026
    Random ASCIIrandomascii.wordpress.com274 people

    There are only four billion floats, so test them all (2014)

    Random ASCII
    Personal · last shared 2026
    PRL Blogprl.ccs.neu.edu24 people

    Measuring GC latencies in Haskell, OCaml, Racket

    PRL Blog
    Company · last shared 2022
    Unhandled Expressionunhandledexpression.com41 people

    Why you should, actually, rewrite some of it in Rust

    Unhandled Expression
    Personal · last shared 2026
    Vidar Holenvidarholen.net68 people

    Useless Use of "dd" (2015)

    Vidar Holen
    Personal · last shared 2025