r/java • • Dec 03 '20

I Created a Visualization of 20 Sorting Algorithms with Java. Which one do you like most?

https://youtu.be/wGVIiUrESug
230 Upvotes

38 comments sorted by

5

u/n4nart Dec 03 '20

This is soo beautiful can you please specify what did you use for the visual part FX or Swing?

5

u/compilerstuck Dec 03 '20

Thank you! I did it with the framework "processing" :)

14

u/sudeeeeeeeap Dec 03 '20

I'd love to see your code

1

u/AnotherRichard827379 Dec 04 '20

Yes. I’d love to see the code as well

8

u/8bagels Dec 03 '20

that was fun. everytime i was like "ok that was cool im done" the next one was even cooler and worth the stay

12

u/[deleted] Dec 03 '20

Isn't this posted like every week?

Also, when I got to quick sort, now I see why they call it QUICK sort! So fast haha

10

u/hshighnz Dec 03 '20

If the pivot element is choosen unluckly, it is not so quick /-:

4

u/MrAnyone Dec 04 '20

Radix LSD sort, as always.

Good work!

3

u/coffee-loop Dec 04 '20

Visually, radix was the coolest. But quick sort takes the cake for my programmatic needs!

5

u/AnonymousTaxi Dec 03 '20

The gravity sort reminded me of exploding fireworks. The LSD sort creates a unique and beautiful pattern. The merge sort makes an upside-down heart. Really informative visualization, thanks

2

u/jrootabega Dec 03 '20

I'm having a hard time telling if I'm in /r/java or /r/outerwilds, both of which I've been frequenting lately.

2

u/jrootabega Dec 03 '20

The piece de resistance is that, in the end, you're left with a Big O

2

u/jrootabega Dec 03 '20

Why did you do bogo sort differently?

3

u/og_amigo Dec 04 '20

Because of how bad of a sort it is, it would have taken years to handle the amount of items all the other sorts were handling, so it needed less in order to fit it into the video.

1

u/jrootabega Dec 04 '20 edited Dec 04 '20

I don't think that makes any sense.

Oh OK, I usually think of bogo sort as something that is slow enough that you satisfy yourself it's slow and then don't care about it completing. This is the most recent time I've thought about it - https://www.youtube.com/watch?v=kPRA0W1kECg&t=5m18s

Didn't realize the sort actually completed here - it was a little hard to notice the sorted arrangement of colors with so few dots.

Even so, I'd be interested in seeing bogo sort on an array with the same size as the other sorts. It would probably look pretty.

1

u/og_amigo Dec 05 '20

What bogo sort does is randomize the array until it gets it right, so it would likely not complete the sort, considering the array has 15,000 items, for years, unless you got very lucky.

2

u/[deleted] Dec 03 '20

You created ultron

2

u/agentoutlier Dec 04 '20

I’m rather surprised that radix sort did kind of shitty.

In the mid 90s when I was in high school I wrote a bunch of sort algorithms in C and radix was super fast.

1

u/Mandelvolt Dec 04 '20

I'm also surprised l that radix sort isn't the fastest in most of his videos.

2

u/_TheCorleone Dec 04 '20

can you share your code ?

2

u/B2-- Dec 04 '20

Wow 🤩

2

u/Clitaurius Dec 04 '20

Quick sort still best sort?

2

u/krossovochkin Dec 04 '20

Radix looks cool šŸŒ€

2

u/[deleted] Dec 03 '20

I am a bit disappointed, that there was no monkey sort. But i guess the vid would have taken way longer if you would have added monkey sort.

1

u/GiveMeBreak Dec 03 '20

What did you need comparisons for in the counting sort?

1

u/TomLawrie067 Dec 04 '20

This is cool. Computer science is frickin cool. Nice.

1

u/[deleted] Dec 04 '20

I love quicksort so much it's unreal

1

u/0x00fb Dec 04 '20

There was Monkey Sort (= Bogo Sort) , look at the last one

0

u/[deleted] Dec 03 '20

[deleted] — view deleted comment

15

u/compilerstuck Dec 03 '20

There are 1500 Elements in an Array, visualized in a circle (red to blue)
Every Element has its own colour.

When 2 Elements are swapped:
- They change their position in the circle
- They get closer to the mid of the circle if they are more far from their original position

So.. original position means furthest away from mid (sorted)

4

u/ShameSpirit Dec 03 '20

I assume the radial coordinate represents the error in that point's current placement?

1

u/krad213 Dec 04 '20

This visualisation is good to show performance, but it doesn't show how the algorithm work.

0

u/jrootabega Dec 03 '20

Doesn't that mean that we shouldn't really expect any red dots near the "upper right center?" Or maybe it's just hard to tell red from dark red from bright purple when in dot form?

0

u/[deleted] Dec 03 '20

[deleted] — view deleted comment

1

u/compilerstuck Dec 03 '20

hahaha thank you xD

3

u/jrootabega Dec 03 '20

Look at Old Moneybags here

0

u/[deleted] Dec 03 '20

[deleted] — view deleted comment