• Allero@lemmy.today
    link
    fedilink
    arrow-up
    8
    ·
    4 hours 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…

  • Swedneck@discuss.tchncs.de
    link
    fedilink
    arrow-up
    18
    ·
    edit-2
    6 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
    
  • TheOakTree@lemm.ee
    link
    fedilink
    arrow-up
    4
    arrow-down
    1
    ·
    5 hours 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?

    • 90s_hacker@reddthat.com
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      4 hours 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

  • fluckx@lemmy.world
    link
    fedilink
    arrow-up
    20
    ·
    8 hours ago

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

    • voldage@lemmy.world
      link
      fedilink
      arrow-up
      9
      ·
      5 hours 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.

  • BatmanAoD@programming.dev
    link
    fedilink
    arrow-up
    116
    ·
    14 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.

    • MajorHavoc@programming.dev
      link
      fedilink
      arrow-up
      25
      ·
      13 hours ago
      // portability
      

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