💤Sleep 🗒Sort

by Ricardo Fernández Serrata

Version 9 (November 22, 2020)

Download (12 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 easily 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". Also, this flow supports non-integers (remember that {random()} only returns integers when its argument is not null) 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) intrinsically 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.

I made this flow as modular as possible, which means you can just throw this inside any flow and it works! (Not exactly, because renaming variables may be necessary. And some blocks are unnecessary if a flow already has them)

COMPLEXITIES (in Big-O Notation):
Worst = O(n^2)
Average = O(n log n)
Standard = O(max + n)
Best = O(n)
This Flow (and some 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

Reviews and ratings can be submitted in the app.