Entertaining but tragically flawed sorting algorithms
Register

User Tag List

Results 1 to 4 of 4
  1. ISO #1

    Entertaining but tragically flawed sorting algorithms

    I present to you...

    Miracle sort!
    Basically, it runs in a loop. And every iteration you check if your list is sorted. If it's not, you skip to the next iteration. If it is, you stop. But the important point is, you never actually change the list yourself.

    Sleep sort!
    This one only works with lists of numbers. For each number N in the list, you make your processor sleep for N time units (where a time unit could be anything from a microsecond to a full second), and afterwards print the number to the screen. Unlike the previous algorithm, this one actually works, but if your list contains a number close to 2^64, you'll be waiting for the answer for about 500 million years (assuming your processor sleeps for a microsecond). I did the math and if you make your processor sleep for exactly N Planck time units, the waiting time is reduced to about a month

    Bogosort!
    Permute the list until it's sorted. This has an insane time complexity of O(n!), meaning that basically if your input source is large enough (probably greater > 100), it will be unbearably slow and very quickly you'll get to a point where you'll actually be waiting for longer than the age of Universe
    Last edited by Oberon; April 23rd, 2021 at 01:36 AM.

  2. ISO #2

  3. ISO #3

  4. ISO #4

    Re: Entertaining but tragically flawed sorting algorithms

    Actually Bogosort is not guaranteed ever to finish, even on finite lists, because it doesn't actually go through each permutation in any specific order - it generates a random permutation.
    This is theoretically unlikely of course, but in practice if you're using a pseudorandom generator, it may be more likely than it seems. Pseudorandom generators are actually functions with an extremely long period, so after a while you'll basically start seeing the same numbers repeating themselves again. If, after one period, you've failed to generate the sorted permutation, then the algorithm is pretty much guaranteed never to terminate.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •