💤Sleep 🗒Sort

by Ricardo Fernández Serrata

Version 9 (April 13, 2021)

Download (19 downloads)

This is not a joke. I thought it was but it's actually useful. This uses multithreading to sort by returning values with a delay based on each of the values themselves.

Of course, most systems and programming languages don't have enough accuracy to keep everything perfectly synced. Thus, for accurate sorting, it's recommended to use a higher delay multiplier. If you want to sort faster, you have higher probability of getting undesired output.

Now, why is this "useful"? Because it's easy and lazy (both the programming and the algorithm itself). It also uses less energy than most sorters, but takes unnecessary time. At least is better than Bogosort lol.

There could be other implementations of this algorithm, like a smart Sleep-Sort that reads all values and automatically adjusts the delays to save time when it detects that some values are very different from the rest. For example, instead of lasting ~110s just to sort [1000, 1, 10] it would last 0.75s by reducing the time difference between values. There could be other implementations that lexicographically sort based on full strings instead of just the 1st char's codepoint.

Automate can't directly detect when ALL child fibers of a parent fiber have stopped running. That's why this uses a Delay/Sleep block instead of "When Fiber Stopped". This flow supports both non-integers and negatives.

The shell script (I've included it for completeness) currently doesn't support Negatives nor strings, and the multiplier doesn't affect it. The shell (not the script) doesn't support Floats, except if your system has BC (Basic Calculator) or AWK, then it could be possible to add float support by editing the script appropriately.

COMPLEXITIES (in Big-O Notation):
Worst = O(n^2)
Average = O(n log n)
Standard = O(max + n)
Best = O(n)
This Flow (and other implementations) = O((((max * multiplier) - (min < 0 ? min : 0)) * 1.05) + n log n)

🗃💾Space (taking everything into account):
Worst = O(2n)
Avg = O(n)
Best = O(log n)

⚡Energy or Power:
W = O(n)
A = O(log n)
B = O(log n)

I must admit that those resource complexities are probably NOT accurate.

Also, thanks to Nice User for pointing out the bug about detecting running fibers

4.5 average rating from 2 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Rate and review within the app in the Community section.