• AlmightySnoo 🐢🇮🇱🇺🇦@lemmy.worldOP
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      1 year ago

      No, n³ cannot be O(n²) as otherwise that would mean that there exists a positive constant K and a positive threshold m such that for any integer n greater than m you would have n³ less than K*n², which would be the same as saying n less than K, which cannot hold for any integer n greater than m. So n³ cannot be an O(n²), which means that something that is an O(n³) is not necessarily an O(n²).

      It’s the other way around, if something is an O(n²) then it is necessarily also an O(n³).

    • MajorHavoc@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Yes. The other answer is technically correct, but yours is pragmatically correct.

      If a solution is worse than O(nln(n))* then most of us are going to be looking for a pragmatic and completely alternate way to deal with it, rather than analyzing how to make it mildly less terrible.

      So I’m just writing O(n^2) as a quick professional replacement for my original write in answer of “dogshit”.

    • MajorHavoc@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Yes.

      And depending how occasionally we’re talking, I can code for some very fast solutions when the correctness requirements are low enough.

      Alternately, if we want it to only be occasionally fast, I’ve got a very nice looking and very wrong algorithm for that, as well.

    • Julian@lemm.ee
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      Any algorithm can be O(1) if you cache all the answers beforehand.