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.
What HN saysHN commenters recommend it as a dose of real-world big-O, noting it shows how abstraction hides complexity, and cite it in language arguments.
72HN people shared it
47linked it in comments
30stories submitted
873story points
7 months agolast shared
2015people per year2026
Most-shared posts
- 1Accidentally Quadratic45 people · 195 points · first shared 2015 · 78 comments on HN
- 2Rust Standard Hash Table Could Go Quadratic11 people · 165 points · first shared 2016 · 18 comments on HN
- 3Algorithmic Complexity of Left-Pad (2016)7 people · 93 points · first shared 2016 · 25 comments on HN
- 4Why Accidentally Quadratic?3 people · 94 points · first shared 2015 · 21 comments on HN
- 5Accidentally Quadratic: Ruby `parser` gem2 people · 4 points · first shared 2016 · discussion on HN
- 6Ruby `reject!`1 people · 306 points · first shared 2017 · 141 comments on HN
- 7Elasticsearch IndicesQuery1 people · 6 points · first shared 2017 · discussion on HN
- 8Accidentally Quadratic – GHC Derived Foldable and Traversable Instances1 people · 5 points · first shared 2015 · discussion on HN
- 9Accidentally Quadratic – Chrome Server-Sent Event Parsing1 people · 2 points · first shared 2016 · discussion on HN
- 10Elegant fix for quadratic mercurial changegroup application1 people · 1 points · first shared 2019 · discussion on HN
- 11Beware the UIKit Visitors – Quadratic Time Complexity Adding Subviews in UIKit1 people · 1 points · first shared 2016 · discussion on HN
- 12Vim TAGS lookup1 people · 1 points · first shared 2017 · discussion on HN
- 13Revisiting haskell network http1 people · first shared 2022
What HN people wrote when they linked it
Aissen · 2021-02-28
It would make a great addition to the Accidentally Quadratic blog: https://accidentallyquadratic.tumblr.com/ (haven't been updated in ~2 years, but maybe the author is around).
tom_mellior · 2017-04-06
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.
fanf2 · 2017-01-04
For a dose of real-world big-O I recommend following http://accidentallyquadratic.tumblr.com
oilywater · 2016-01-16
http://accidentallyquadratic.tumblr.com/
Great blog with examples where something linear turns quadratic! :D
Most of the examples show that being this high at the abstraction level disallows you to properly evaluate the complexity of the code you are writing. Something that might look simple and linear can in fact have a quadratic behavior.
jerf · 2023-06-01
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…
btilly · 2025-09-12
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.
nemetroid · 2023-11-14
This is how we end up with https://accidentallyquadratic.tumblr.com/.
chriswarbo · 2023-08-17
The "accidentally quadratic" blog collected such things. Not sure if it's still being updated since Tumblr's mass exodus (the posts don't seem to show timestamps) https://accidentallyquadratic.tumblr.com
fragmede · 2023-07-30
If you haven't seen it, Accidentally Quadratic has a tumblr documenting those kinds of things. https://accidentallyquadratic.tumblr.com/
dangerlibrary · 2023-05-19
For a collection of similar stories:
https://accidentallyquadratic.tumblr.com/
vjeux · 2022-07-23
If you want to see more examples of accidentally quadratic behaviors: https://accidentallyquadratic.tumblr.com/
mrami · 2022-06-20
Quadratic behavior is O(n^2) like bubblesort - triple the number of items to sort, and it takes 9x the time.
Really, the comment was referring to "accidentally quadratic" bugs, as documented here, for example: https://accidentallyquadratic.tumblr.com/
smasher164 · 2021-03-01
Sounds like a new entry for https://accidentallyquadratic.tumblr.com/?
EdSchouten · 2021-02-28
Both of these issues are good candidates for https://accidentallyquadratic.tumblr.com
tomsmeding · 2020-08-30
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/
xxpor · 2020-08-20
It's a good check on yourself though. Even if you don't know formal big-O, knowing that something that's O(n) will be faster than O(n!) is pretty important.
People who don't realize this end up here: https://accidentallyquadratic.tumblr.com/ :)
db48x · 2020-08-06
You should send that to Accidentally Quadratic (https://accidentallyquadratic.tumblr.com/). There have been no new stories there in a year, but perhaps they just need submissions.
masklinn · 2019-12-09
> it often arises from one O(n) algorithm calling another O(n) algorithm in each iteration, resulting in O(n^2) overall.
https://accidentallyquadratic.tumblr.com was / is pretty much an entire blog dedicated to this.
strmpnk · 2018-10-16
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.
andybak · 2018-08-02
Gosh. One for https://accidentallyquadratic.tumblr.com/ with the added spice of being on usage billing...
userbinator · 2017-10-19
Also related: https://accidentallyquadratic.tumblr.com/ examples of where, due to abstraction or otherwise, a quadratic or even worse algorithm emerges, and is not obvious from a quick glance since the multiple nested loops are separated out from each other.
pacaro · 2017-04-17
Accidentally quadratic is good for a chuckle too
https://accidentallyquadratic.tumblr.com
adrianN · 2017-03-16
"It's okay for my n!" http://accidentallyquadratic.tumblr.com/
Retr0spectrum · 2016-07-20
For more bugs caused by quadratic complexity:
http://accidentallyquadratic.tumblr.com/
to3m · 2016-05-27
There's an explanatory post there that in particular is very much worth reading: http://accidentallyquadratic.tumblr.com/post/113840433022/why-accident…
mpweiher · 2016-05-14
Good sleuthing, sounds like an instance of "accidentally quadratic"[1]. It's a very easy thing to miss, especially if n is usually small.
[1] http://accidentallyquadratic.tumblr.com
serve_yay · 2015-03-24
Indeed, you don't!
And we all look forward to your app being featured on http://accidentallyquadratic.tumblr.com :)
deathanatos · 2022-05-14
> 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…