• riwo@lemmy.blahaj.zone
    link
    fedilink
    English
    arrow-up
    14
    ·
    12 hours ago

    it really only has a time complexity of O(1) for the first few items though. beyond that it increases to O(n) again

    • Azzu@leminal.space
      link
      fedilink
      English
      arrow-up
      11
      ·
      edit-2
      12 hours ago

      Well you’re supposed to keep the structure an array, not let it become a stack.

      • Sophienomenal@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        5 hours ago

        Unfortunately, though the reserved memory is sequential, the order in which items are added is pseudorandom, and gravity prevents random access, so you would still need a linear search of O(n) time to find any given item.