News for hackers. Stuff that matters.
Re:Learn Big-O and stop hacking your way through algorithms by cmckn on Thursday August 20, 2020 @07:09PM (#24230080)
> 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.

There are no comments on this comment yet.