r/Python • • Jan 11 '20

Python Sorting Algorithm Visualizer (Using Cocktail Shaker Sort Algorithm)

1.3k Upvotes

41 comments sorted by

20

u/Sklyvan Jan 11 '20

Since some of you are asking for the source code, I uploaded it to GitHub: https://github.com/Sklyvan/Array_Visualizer

3

u/thblckjkr Jan 11 '20

The code is smaller than I thought it would be. I love it.

28

u/tobb10001 Jan 11 '20

I love watching storing algorithms. Do you have a repo with the code?

5

u/nemom Jan 11 '20

I love watching storing algorithms.

What, like... Pickle or tar-bzip2?

3

u/tobb10001 Jan 11 '20

Exactly.

I didn't know storing algorithms are a thing until just a few seconds ago but definitely.

This happens to me to often...

75

u/sxsnyc Jan 11 '20

If anyone is wondering complexity is O(n^2).

23

u/[deleted] Jan 11 '20

Too bad! It looks so neat. 😍

5

u/ixJax Jan 11 '20

For anyone that doesn't what this means (I didn't until a week or so ago), Tom Scott has a video on it

9

u/golfreak923 Jan 11 '20

Came here for this

1

u/notneeson Jan 12 '20 edited Jan 12 '20

What is it like weirdly higher efficiency for relatively sorted lists or something?

Edit: Oof it is 2 sided bubble sort. One of the the simplest, least efficient sorts but it does look cool.

1

u/Stelercus Python Discord Staff Jan 12 '20

I assume it uses this sort instead of a more efficient sort because it uses however > and < are implemented for each class, regardless of which types are being compared. That is to say, it's not guaranteed that sort will be sorting numerical types.

10

u/[deleted] Jan 11 '20

8

u/The-Cynical-One Jan 11 '20

The classic double bubble trouble sort... how magnificent.

2

u/Wilfred-kun Jan 11 '20

Unexpected bubble trouble... Almost feels nostalgic.

1

u/DefMech Jan 11 '20

It’s pop-o-matic!

5

u/PancakeLizard69 Jan 11 '20

You mind explains how the cocktail shaker sort works?

0

u/[deleted] Jan 11 '20

[deleted]

4

u/[deleted] Jan 11 '20

How does it compare to other algorithms

17

u/foxx1337 Jan 11 '20

Right at the bottom.

0

u/[deleted] Jan 11 '20

[deleted]

6

u/[deleted] Jan 11 '20

And randomly sorting

4

u/[deleted] Jan 11 '20

This is almost as satisfying to watch as when the DVD logo finally hits the corner of the screen!

1

u/niigupta3008 Jan 12 '20

I am sorry but I have to ask this. I want to do this kind of visualisation too, but I know only basic python. How can I reach this level? What all do I need to know?

1

u/Sklyvan Jan 12 '20

You should know abou Sorting Algorithms (Which is easy), and then know how to use some Graphical Libraries, in this case PyGame.

2

u/frasercampbell_ Jan 11 '20

me shuffling my uno cards

1

u/brain_tourist Jan 11 '20

God this is satisfying

1

u/karlkloppenborg Jan 11 '20

Sooooooo satisfying!!!

1

u/[deleted] Jan 11 '20

Looks like the oppositeof the candle lit at both ends sorting algorithm, but faster.

1

u/paul_flan84 Jan 12 '20

Data is beautiful

1

u/69shaolin69 Jan 12 '20

Visualize bob-sort

I forgot the name but it’s the one where you randomize the list and hope for the best

1

u/[deleted] Jan 12 '20

no more jet colormap please ;)

0

u/[deleted] Jan 11 '20

[deleted]

32

u/[deleted] Jan 11 '20

Whoa spoilers!

5

u/SciDawg Jan 11 '20

I'm so happy you are here. ♥️

1

u/[deleted] Jan 11 '20

[removed] — view removed comment

1

u/RemindMeBot Jan 11 '20

There is a 1.4 hour delay fetching comments.

I will be messaging you in 14 hours on 2020-01-12 10:40:06 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback