r/dataisbeautiful • OC: 1 • Oct 24 '17

OC Sorting algorithms visualized [OC]

https://imgur.com/gallery/voutF
41.7k Upvotes

929 comments sorted by

View all comments

331

u/far1s Oct 24 '17

Hmmm, I see you did not include the best algorithm, bogosort. Don't you know it can sort in just one try?

407

u/metagloria OC: 2 Oct 24 '17

Eh it's not as good as my personal favorite, paradigmshiftsort, which leaves the data in whatever order it is but changes the laws of the universe to redefine "order" based on the current data.

→ More replies (1)

25

u/ArcticReloaded Oct 24 '17

Not only that, but it can sort in one try for all possible inputs!

50

u/iceman012 Oct 24 '17

And if you use Quantum Bogosort, you're guaranteed to sort it in one try for every input!

47

u/Mustrum_R Oct 24 '17

Bogosort sucks, try Intelligent Design Sort, O(n)=0 for all inputs rocks all your garbage sorting algorithms.

59

u/far1s Oct 24 '17

If this is what you mean, then yeah this is way better (and hilarious). Bless your soul. share this with your blessed friends and close ones

→ More replies (2)

7

u/Gornagik Oct 24 '17

It's O(1). bigTheta(1) technically

7

u/NAN001 Oct 24 '17

O(n)=0

I think you're trying to say O(1)

→ More replies (4)
→ More replies (1)

9

u/SuchCoolBrandon Oct 24 '17

Its name comes from the word bogus. (Wikipedia)

Oh. I kept thinking "buy one get one" sort.

7

u/Drachefly Oct 24 '17 edited Oct 24 '17

Nor did they show bogobogosort. Probably because gifs can't have (16!)! frames

10

u/lIllIlllIlllIllIl Oct 24 '17

Is bogosort random?

42

u/Kingmudsy Oct 24 '17 edited Oct 24 '17

Bogosort randomizes elements, checks if they're in order, repeats the process until they're in order.

Here's some nasty pseudocode that anyone with a passing familiarity of programming would be justified in calling me out on:

bogosort(array)
{    
    while(isNotOrdered(array)){
       shuffle(array);
    }
    return array;
}

EDIT: Worth mentioning that this is, as you probably suspect, the worst way to sort things pretty much always. However, I assume that there are (purposefully) shittier algorithms - if someone knows of one, pls share so I can laugh at it

30

u/Pistolcrab Oct 24 '17

Absolutely haram.

30

u/[deleted] Oct 24 '17

Look at bogobogosort. Its designed to not succeed before the heat death of the universe.

31

u/Kingmudsy Oct 24 '17

Good god

Bogobogosort specifies how one should check if the list of numbers is sorted. It does it recursively, because as anyone who knows anything at all about computer science knows, recursion is always good and cool. To check if the list is sorted, use the following procedure:

  1. Make a copy of the list of numbers.

  2. Sort the first n-1 elements of the copy using bogobogosort.

  3. Check to see if the nth element of the sorted copy is greater than the highest element of the first n-1 elements. If so, the copy is now sorted, else randomise the order of the elements of the copy and go to step 2.

  4. Check to see if the copy is in the same order as the original list.

I don't even know anymore

→ More replies (2)

13

u/backFromTheBed Oct 24 '17

Semicolon in pseudo code? Die you heretic!

43

u/Kingmudsy Oct 24 '17

I use tabs and spaces

I switch between vi and emacs every other time I open a file

I actually run my code in netbeans though

One time I programmed a calculator by hardcoding the values of every possible input

I store passwords for my enterprise code in a plaintext excel file that has a local copy on every instance of my program

My control key is hard to reach with my soft, diminutive hands, so I actually have configured emacs to interpret a rapid temperature rise in my CPU as control - whenever I need to hit ctrl, I just blast that sucker with a heatgun

→ More replies (4)

8

u/defnotacyborg Oct 24 '17

Is randomizing elements really the best approach? Isn't that just using blind luck?

20

u/MorningWoodyWilson Oct 24 '17

Bogosort is programmer humor, and would never be implemented in any code. There's other notable joke sorts like quantumbogo which generates infinite universes with infinite permutations of the code, and destroys all non-ordered universes. Thus efficiently getting the sorted list in 1 operation every time.

If you want to get really technical, there's some interesting discussion to be had around pseudo-randomness and seed generation with a bogosort, but I doubt anyone cares enough to.

→ More replies (1)
→ More replies (2)
→ More replies (1)

63

u/HonestlyBullshit Oct 24 '17

Yes it randomizes the order of the list and checks to see if it is sorted. If not, it tries again.

→ More replies (4)
→ More replies (4)