• grue@lemmy.world
    link
    fedilink
    English
    arrow-up
    26
    ·
    7 hours ago

    You want to think your pile is O(1) for retrieval, but it’s actually O(n).

    Meanwhile, the closet actually is O(1) for retrieval, but you don’t want to spend the time for the bulk insert it requires beforehand.

    • tetris11@feddit.uk
      link
      fedilink
      English
      arrow-up
      7
      ·
      edit-2
      4 hours ago
      • O(n) worst case
      • O(log(n)) average case
      • O(1) best case
      • O(2) median case

      That last one: it’s a LIFO stack. You might not immediately wear what you threw on last night, but probably would wear the thong under that

    • socsa@piefed.social
      link
      fedilink
      English
      arrow-up
      4
      ·
      6 hours ago

      Yeah I was going to say - unless your pile is ordered and indexed then it is not a cache and is more like random access.

      • grue@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        4 hours ago

        A pile is a messy stack, with access to push and pop only from the top. It is ordered (from the top down), but not indexed.

    • Noodle07@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      6 hours ago

      Now if you store things in vertical stacks only accessible from above… Yeah I keep my clothes on the drying rack so I spend 0 time storing anything lol