Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Sort Algorithms - What they sound like!?!?

Author
Message
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Jun 2012 05:40
I've just come across this on this page and found it very unusual to find that some people have gone to lengths to produce actual audio from different sorting algorithms.

And I'd thought I'd share it...

Most of the time I just use a straight forward bubble sort, just swapping values over. I'm still trying to find faster methods for larger data sets were I have to compare something like three floats.

ie:



Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Nateholio
19
Years of Service
User Offline
Joined: 30th Dec 2005
Location: I\'ve Been Everywhere
Posted: 1st Jun 2012 08:59
That's pretty darn cool! But I'm a major geek....

In Development: K96 - Combat Simulation
Keep your Hope and Change, I choose individual Liberty!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Jun 2012 10:53
Quote: "Most of the time I just use a straight forward bubble sort,"

I think it's time to step it up a notch. The bubble sort isn't the most efficient sort in the arsenal. Try a mergesort or quicksort as both of these are O(log n) time. The only problem I see with a mergesort however, is that for large data sets, it could overflow the stack since it makes use of recursion, but you'd have to have a very large data set to do that.

Those sounds are awesome though!

Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 1st Jun 2012 18:31
Is it bad that I find the sound of the values gradually ordering up strangeley beautiful? Merge sort is the most compelling sound for me I think.

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Jun 2012 18:40
Quote: "Try a mergesort or quicksort as both of these are O(log n) time."


Erm, quicksort is O(n²) worst case and mergesort is O(n log n) worst case. They are both O(n log n) on average. (It's impossible to get on average better than O(n log n) in a comparison sort.)

[b]
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st Jun 2012 18:45
What's the alternative to a comparison sort?

MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Jun 2012 18:46


Made My Year!!!

budokaiman
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 1st Jun 2012 18:59
Quote: "What's the alternative to a comparison sort?"

Radix sort is one.
http://en.wikipedia.org/wiki/Radix_sort


3DS friend code: 0044-2895-5474
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Jun 2012 19:04
Quote: "What's the alternative to a comparison sort?"


There are other sorting algorithms which don't depend on comparisons to function, for example radix sort operates in O(n) time.

A simple example is if you have numbers between 1 and 5 that you want to sort:
5
1
3
4
3

First you count how many of each number there are:
1: 1
2: 0
3: 2
4: 1
5: 1

Then you sum those values to find how many items are less than each number:
< 1: 0
< 2: 1
< 3: 1
< 4: 3
< 5: 4

This tells you exactly where to put each item. The first item is a 5, so you look in the array and see that there are 4 numbers less than 5, so 5 must go in the 5th position. At the same time you increase the value in the counting array. Repeating this process:

Next input: 5
Count: {0, 1, 1, 3, 4}
Result: {x, x, x, x, 5}
New count: {0, 1, 1, 3, 5}

Next input: 1
Count: {0, 1, 1, 3, 5}
Result: {1, x, x, x, 5}
New count: {1, 1, 1, 3, 5}

Next input: 3
Count: {1, 1, 1, 3, 5}
Result: {1, x, 3, x, 5}
New count: {1, 1, 2, 3, 5}

Next input: 4
Count: {1, 1, 2, 3, 5}
Result: {1, x, 3, 4, 5}
New count: {1, 1, 2, 4, 5}

Next input: 3
Count: {1, 1, 2, 3, 5}
Result: {1, 3, 3, 4, 5}
New count: {1, 1, 3, 4, 5}

Obviously you would normally use this on much larger ranges than 1-5. You would normally do this process multiple times, so if you were sorting 4 byte integers, the count array would be far too big, so you might do it one byte at a time, so you'd only have to use an array with 256 items in.

If you want a better explanation, Paul explained it very well at the last TGC convention, the videos of which should still be around somewhere.

[b]
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st Jun 2012 19:06
That was a good explanation, thanks. How does the speed compare?

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Jun 2012 19:22
As you can see, for each sorting pass you have to go through the items array at least twice, and the counting array once, so let's say the cost is:
cost = (2n+c)p
Where p is the number of passes.

For a good comparison sort, such as merge sort, O(n log n) comparisons are needed:
cost = n log n

With the example input data of arbitrary 4 byte integers, p = 4, c = 256:
radix sort cost: (2n+256)*4 = 8n+1024
merge sort cost: n log n

By plotting this you can see that radix sort becomes faster at around 700 items. This is only a rough estimate but it will be on the order of 1000 items.

[b]
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Jun 2012 21:57
After seeing that Hungarian dance thing, I now want to know that the radix sort sounds like...

On a serious note though, the radix sort seems to be the method I'll be looking into. I'm trying to figure how to sort faces and indices in order a quicker way.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Jun 2012 22:37
I want to make a program based on the Hungarian video with little animated characters doing the dancing. So you could input any numbers and it would sort them Hungarian style.

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Jun 2012 22:44
Yeah I thought that too.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Jun 2012 23:03
Quote: "Erm, quicksort is O(n²) worst case and mergesort is O(n log n) worst case. They are both O(n log n) on average. "

That's what I meant. Although, I didn't know about Quicksort's worst case scenario.

WLGfx, can you find sounds for the Bogosort?

The Weeping Corpse
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Jun 2012 03:39
ha ha... Just looked up bogosort on google... Probably get just white noise...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2025-05-19 01:44:52
Your offset time is: 2025-05-19 01:44:52