• @[email protected]
    link
    fedilink
    214 minutes ago

    The most beautiful thing about this program is that it would work.

    Various bit flips will once lead to all numbers being in the correct order. No guarantee the numbers will be the same, though…

  • @[email protected]
    link
    fedilink
    237 minutes ago

    Hello programmers…

    I recently took a course that went through basic python, C, and C++.

    I had a hard time implementing various forms of sorting functions by hand (these were exercises for exam study). Are there any resources you folks would recommend so that I can build a better grasp of sorting implementations and efficiency?

    • @[email protected]
      link
      fedilink
      1
      edit-2
      8 minutes ago

      Skiena’s Algorithm design manual is very widely recommended for learning algorithms, I’ve also heard good things about A common sense guide to algorithms and data structures. Skiena’s also has video lectures on YouTube if you prefer videos.

      From what I’ve seen, a common sense guide seems to be more geared towards newer programmers while Skiena assumes more experience. Consequently, Skiena goes into more depth while A common sense guide seems to be more focused on what you specifically asked for. algorithm design manual

      A common sense guide

  • @[email protected]
    link
    fedilink
    10
    edit-2
    2 hours ago
    import yhwh  
    
    def interventionSort(unsortedList):
        sortedList = yhwh.pray(
        "Oh great and merciful Lord above, let thine glory shine upon yonder list!", 
        unsortedList
        )  
        return sortedList
    
  • @[email protected]
    link
    fedilink
    194 hours ago

    I prefer the one where you randomly sorting the array until all elements are in order. ( Bogosort )

    • @[email protected]
      link
      fedilink
      448 minutes 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.

    • Ephera
      link
      fedilink
      265 hours ago

      I hear, it actually significantly increases the chance of the miracle occurring when you pass the array into multiple threads. It’s a very mysterious algorithm.

  • @[email protected]
    link
    fedilink
    807 hours ago

    My favorite is StalinSort. You go through the list and eliminate all elements which are not in line.

  • @[email protected]
    link
    fedilink
    10110 hours ago

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

    • NaN
      link
      fedilink
      136 hours ago

      Instead of destroying the universe, can we destroy prior, failed shuffle/check iterations to retain o(1)? Then we wouldn’t have to reload all of creation into RAM.

      • @[email protected]
        link
        fedilink
        44 hours ago

        Delete prior iterations of the loop in the same timeline? I’m not sure there’s anything in quantum mechanics to permit that…

    • @[email protected]
      link
      fedilink
      689 hours ago

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

      • @jcgA
        link
        23
        edit-2
        9 hours ago

        is-sorted and a handful of about 300 other npm packages. Cloning the repo and installing takes about 16 hours but after that you’re pretty much good for the rest of eternity

    • @[email protected]
      link
      fedilink
      29 hours ago

      Since randomizing the list increases entropy, it could theoretically make your cpu cooler just before it destroys the universe.

    • @[email protected]
      link
      fedilink
      269 hours ago
      // portability
      

      Gave me the giggles. I’ve helped maintain systems where this portable solution would have left everyone better off.