r/oddlysatisfying • • Sep 02 '19

Learn sorting algorithm with Kronk

8.9k Upvotes

58 comments sorted by

446

u/stillakilla18 Sep 02 '19

Supposedly OP says it's slowed for some so they all finish together.

239

u/Mr_Redstoner Oh yes Sep 02 '19

Definitelly. Especially for big inputs, Bubblesort will be monumentally slow compared to quicksort for exapmle. When I was doing some testing, giving both identical arrays of 10 000 000 elements quicksort took ~0.1 seconds... bubblesort took 50 seconds

41

u/[deleted] Sep 03 '19

And bogo sort is still running

2

u/[deleted] Sep 03 '19

It depends in the input if its almost sorted bubble sort is better

→ More replies (3)

1

u/BluudLust Sep 03 '19

It's called quick for a reason.

49

u/Archknits Sep 02 '19

This bothered me a lor

12

u/[deleted] Sep 03 '19

You say supposedly as if this there’s a chance he’s lying. He isn’t, that’s how algorithms work. They complete their tasks at varying speeds depending on which approach you use to solve a problem. Look at OPs speeds in Big O notation and go research Big O notation.

11

u/SplendidPunkinButter Sep 03 '19

Or, if you don’t want to go research an entire non-trivial subject just to understand a Reddit post, suffice it to say that these sorting algorithms vary wildly in how efficient they are. So if they all finished at the same time here, that indicates that some of them have been slowed down, because you would in no way expect all of them to finish at the same time.

2

u/eeeyuyt4 Sep 03 '19

Yeah I was like WTF kind of data do you have where bubblesort is the fastest... Realized it had to be sped up SMH.

1

u/RearEchelon Sep 03 '19

Has to be. Otherwise why use different ones?

54

u/uprightbaseball Sep 02 '19

Can someone give a concise/ simplified overview of each of the sorting algorithms?

87

u/Mr_Redstoner Oh yes Sep 02 '19 edited Sep 03 '19

Not quite all, but here goes:

Selection: find the next smallest, put it in place

Insertion: find the place for the current one

Bubble: keep going from one side to the other, every time you spot adjacent elements in the wrong order swap them

Cocktail: Bubble but going both ways

Merge: Split it in half, mergesort each half, then join them by always taking the next smallest element from those parts

Quick: Pick one (the 'pivot'), put all smaller before it and all bigger after it. Then quicksort the smaller ones and the bigger ones

15

u/Komlz Sep 02 '19

If you were just looking for speed, which would be the best?

22

u/erasmause Sep 02 '19

Usually quicksort, thoughfor pathological inputs, it can perform as poorly as bubble sort, but there are steps that can be taken to mitigate this. Heapsort is usually a bit slower in practice, but has better worst-case behavior. Neither are stable, though (a stable sitting algorithm guarantees that elements that are equivalent under the comparison function appear in the same relative order in the output as they were in the input; this can matter if the comparator only considers a subset of the value, like sorting people by age). Mergesort is in the same ballpark (better, in some specific scenarios) and is stable, but usually requires extra memory proportional to the input (some implementations reduce or eliminate this by sacrificing stability or a bit of performance).

In practice, most sort utilities provided in e.g. standard libraries are adaptive hybrids (for instance using quicksort at the top level, but once it gets down to sublists of a certain size, switching over to a simpler selection it insertion sort, or the block sort variant of mergesort).

4

u/Mr_Redstoner Oh yes Sep 03 '19

Do note that quicksort can be stable. IIRC the version that was used in Java's Arrays.sort was.

→ More replies (3)

4

u/Mr_Redstoner Oh yes Sep 03 '19

If pure speed matters a lot, you could also use Intelligent design sort, which runs in constant (0) time with no resources:

The probability of the original input list being in the exact order it's in is 1/(n!). There is such a small likelihood of this that it's clearly absurd to say that this happened by chance, so it must have been consciously put in that order by an intelligent Sorter. Therefore it's safe to assume that it's already optimally Sorted in some way that transcends our naïve mortal understanding of "ascending order". Any attempt to change that order to conform to our own preconceptions would actually make it less sorted.

- http://www.dangermouse.net/esoteric/intelligentdesignsort.html

And yes, there are other joke sorts like this.

→ More replies (1)

8

u/jamesianm Sep 03 '19

Cocktail: Bubble but

Bubble bubble bubble but

1

u/Terakahn Sep 03 '19

How does this help it rearrange pixels in a picture?

→ More replies (1)

22

u/WG55 Sep 03 '19

Still my favorite computer sort video: 15 Sorting Algorithms in 6 Minutes

4

u/andybest277 Sep 03 '19

4

u/WG55 Sep 03 '19

LOL, yeah. Wikipedia says it is also called "permutation sort, stupid sort, slowsort, shotgun sort or monkey sort" and is nothing but random permutations until the data just happens to be sorted.

2

u/Nyr3105 Sep 03 '19

slowsort is confusing, for theres an actual "slowsort", being similar to the mergesort, though applying the "multiply and surrender" principle instead of the mergesorts "divide and conquer"

3

u/Joylime Sep 03 '19

VERY GOOD!!!

45

u/mymom964 Sep 02 '19

Oh yeah it’s all coming together

8

u/[deleted] Sep 02 '19

Bottom left looks like a flat rubix cube being solved

4

u/[deleted] Sep 02 '19

Takes me back to my degree

4

u/jabhwakins Sep 03 '19

Normalizing them all to finish at the same time is very not satisfying to me.

3

u/Trapezoidoid Sep 03 '19

I can’t stop watching this. It’s mesmerizing.

1

u/sparkjournal Sep 03 '19

Careful you don't stare into the Kronk. The Kronk might stare back.

3

u/Thatoneshadowking Sep 03 '19

KRONK, activate the algorithm

WRONG ALGORITHM

2

u/OaIei Sep 03 '19

Where's my mans bogo sort

2

u/Ikillesuper Sep 03 '19

I read that as “line snorting” I have a problem

2

u/imeannotalways Sep 03 '19

"Oh, riiight. The poison. The poison for Kuzco. The poison chosen 'specially to kill Kuzco. Kuzco's poison......... that poison?"

1

u/RemmyTheWyrm Sep 02 '19

for a second i was thinking "what the fuck am i looking at" until it started coming together

1

u/akisk2000 Sep 03 '19

Where is bogosort?

1

u/FacePalmWithNapalm Sep 03 '19

That's extremely misleading on the timing difference. This bothers me a lot

1

u/Yun6013 Sep 03 '19

I feel like I got Rick rolled hard when he said the subtitles

1

u/One_T_Scot Sep 03 '19

Insertion looks like when we tried watching scrambled porn in the 90s

1

u/No_Sale_5172 Apr 01 '23

how can i implement this in python

1

u/[deleted] Sep 03 '19

[removed] — view removed comment

1

u/JaykDoe Sep 03 '19

Oh ya and looking at porn on AOL dial-up in the 90's. Totally reminds me of that too!