Hacker News new | ask | show | jobs
by Sharlin 551 days ago
More accidentally quadratic stories: https://www.tumblr.com/accidentallyquadratic
1 comments

A classic. Every time I see that link I read the whole thing starting from the new beginning.

...oops

I opened the link and just started reading. I have a really dumb question that may expose common knowledge I don’t have, about this quote:

> The total amount of space needed to represent this collection of strings is O(k n^2).

I haven’t seen O-notation ever represent ram usage, just algorithm complexity. Is this common?

Yes, very common. You've seen "time complexity"; it's very common to talk about "space complexity" as well.
Fun bonus: they can be interchangeable, e.g. increasing space to reduce time.
And any operation that takes n bits as input can be trivially turned into an O(1) time and O(2^n) space algorithm through tabulation.
Assuming you ignore or amortize the time necessary to create the table in the first place, of course.

This is the basis for rainbow tables: precomputed tables for mapping hashes to passwords, with a space-saving “hash chaining” trick to effect a constant factor reduction in table size. Such tables are the reason why passwords must be hashed with a unique salt when stored in a database.

Yes, but total time is never going to be less than total space, when expressed in big-O notation
I’m not sure this definition of Big-O for space complexity is universal. When I’ve seen/used it, the size of the initial data wasn’t relevant, it was more about the additional memory required for the algorithm.

For example, an in-place algorithm like Bubble Sort would have a O(1) space complexity, because it requires no extra memory (and 0 memory is a constant). Merge sort on the other hand is O(n) because it always uses additional memory for its intermediate stages, and that additional memory scales with n.

Doing a quick google, the first few sites I find seem to use a similar understanding https://www.geeksforgeeks.org/time-and-space-complexity-anal...

Why couldn’t it?
> Is this common?

Very. For instance if you look at sorting algorithms on wikipedia they pretty much all list performance (best, worst, average) but also worst-case space complexity, in O notation.

Is there a way to do that without signing in?