3 ms·
> I think it’s way harder coming up with complex algorithms in the first place. As soon as you start utilizing a data structure or calling another function, un
by cmckn 6y ago
> I think it’s way harder coming up with complex algorithms in the first place.
As soon as you start utilizing a data structure or calling another function, understanding the asymptotic behavior of each call can be super helpful. For example:
public void f(List a, List b) {
for(Object o : a) {
if(b.contains(a)) {
b.remove(a);
}
}
}
This might look like O(a), but is O(a*b), because `contains` and `remove` are O(n). I've come across code at work that was quadratic or much worse because of things like this. Whether or not this matters is more of a wash; if these lists only have 10 elements, meh
Big O can also be misleading; modern computers may execute some optimal algorithm slower than a less optimal one, because of cache performance or whatever.