3ICE's Bucket Sort demonstration


Data

Pseudocode:

myBucketSort(names): buckets = new array[] for each name in the names array: create bucket if first letter is new insert name into buckets[ firstLetterOf(name) ] result = new array[] for each bucket: Insertion Sort the contents concatenate into result return the result

Optimization possibilities

DONE: I was using JavaScript's generic sort() function on the whole data set after bucket sort completed. (The objects were first collected from each bucket.) Using Insertion sort is far more efficient here, so I implemented it.

DONE: Collecting the objects from each bucket was done one by one. If we use a linked list instead of an array, we can speed up the process.

WONTFIX: The whole code is a big old hack job done in 200 lines of JavaScript, but at least it demonstrates the bucket sort algorithm with neat animations. (Thanks, jQuery!)

Credits

Created with Notepad++ and Google Chrome, using jQuery (my very first time using jQuery!), by Daniel "3ICE" Berezvai on 2014. 02. 18. Updated on 2014. 03. 04.

Valid HTML5 and CSS3. Works in Chrome, Opera, Firefox, and IE. (Safari however, doesn't seem to like me: Slow and the two buttons responsible for resetting and prepopulating the textarea kept failing, but I got it to work in the end.)