• BatmanAoD@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    2 months ago

    Reminds me of quantum-bogosort: randomize the list; check if it is sorted. If it is, you’re done; otherwise, destroy this universe.

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      Guaranteed to sort the list in nearly instantaneous time and with absolutely no downsides that are capable of objecting.

      • frezik@midwest.social
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        You still have to check that it’s sorted, which is O(n).

        We’ll also assume that destroying the universe takes constant time.

          • groet@feddit.org
            link
            fedilink
            English
            arrow-up
            0
            ·
            2 months ago

            It actually takes a few trillion years but its fine because we just stop considering the “failed” universes because they will be gone soon™ anyway.

    • voldage@lemmy.world
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      2 months ago

      I don’t think you can check if array of n elements is sorted in O(1), if you skip the check though and just assume it is sorted now (have faith), then the time would be constant, depending on how long you’re willing to wait until the miracle happens. As long as MTM (Mean Time to Miracle) is constant, the faithfull miracle sort has O(1) time complexity, even if MTM is infinite. Faithless miracle sort has at best the complexity of the algorithm that checks if the array is sorted.

      Technically you can to down to O(0) if you assume all array are always sorted.