by andrewvc · 13y ago · 0 comments
I use the spirt of Big-O almost daily, but do the actual calculations rarely, and basically never use the notation. With some experience, you quickly get an intuitive feel for execution time, which is good enough in most cases.
Additionally, when writing an API for use by other developers its useful to say, this operation runs in constant time, that one in logarithmic time.
Redis, for example, mentions the computational complexity of all operations in its docs. Additionally, everyone should know that most decent sorting algorithms are O(n log n), and understand the implications of that.
Zarel: and for insertions, aren't they O(nm) for n insertions into a list of size m either way?
Cathy: inserting n elements into a list of size m when done with queueing requires at most m iterations
Cathy: when not done using a queue, it requires at most n*m iterations
Cathy: a factor of n is the difference
Cathy: of course, n might be pretty small, depending on how many insertions happen in the debounce wnidow
Cathy: n might be 10-15
Zarel: how do you insert n elements into a list of size m in m iterations?
Cathy: iterate over the list of m elements
Cathy: well, i guess you'd need to sort the list of n elements first
Zarel: oh, I see, I forgot about sorting the list
Zarel: so it'd be O(n+m)
Zarel: which is admittedly much faster for our purposes
Zarel: well, considering n is likely to be approximately 5, "much" might be an exaggeration
Cathy: in any case, i agree that inserting/deletion approach is the right way to do this
Zarel: incidentally if we wanted we could apply certain optimizations to improve an insertion from O(n)
Zarel: for instance, binary search
Cathy: it's not immediately obvious whether that is faster than the sorted queued
Zarel: actually, that's not a bad idea regardless
Cathy: but it's certainly faster than the naive single insertion
Zarel: I mean, O(n log m) is significantly faster than O(n+m)
Zarel: when n is ~5 and m is ~1500
Cathy: true, and it actually makes it clear that using a queue is unnecessary
I don't know of a better way to discuss optimizing an inner loop than to use big O notation.And even if you are facing problems that mandate you to roll out your stuff how much of that requires these math tricks.
Given all this, if you truly want to hire a math geek to get some magic done. I guess you are looking at a very small pool of people to hire from and it should hardly be a problem to hire one.
Big-O notation is pretty basic, and very useful. Combined with a memorized table of powers of two (you don't need all of them - I know up to 2^20, and this has proven sufficient - just enough so you can guess log N for a given value) you have a good chance at being able to make quick calculations about time and space requirements for things. Which, since we don't have infinitely fast computers with infinite amounts of memory, often comes in handy.
Besides that I still don't understand this. I don't even know the last time anybody around me ever had a problem or a show stopper problem anything to do with Big-O or an algorithm.
Its always how the programmer can take pressure, how he can contribute to making the project happen, getting things done, how he can collaborate with fellow team mates, how he responds under times of crisis, how good he is with tools, what are his everyday practices, does he write unit tests, does he do code reviews, does he document the API's he writes, how does he package his code, how update he is with software world(tools, framework and techniques) etc etc.
Lets be frank, Its always these things that are relevant today in practical everyday software projects today. Unfortunately people hardly ask questions on these and then complain of bad software practices among people these days.
I guess what I'm trying to say is that Big-O between a Set and Array do not matter if you can't use a set to begin with. If the problem fits a set then using a set is right regardless of the performance implications.
I do agree with your overall premise of laziness though. Most programmers default to a list likely because it is the first thing ever taught, and for some reason rarely think beyond it. For me, part of the fun of solving coding problems is finding the best fit data structure :)