| Ultrashock Forums
• Share Data Structures & Algorithms |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
|
2005-04-05
#2 |
||
|
Quick Sort
Last edited by Mike : 2006-06-11 at 04:32.
Note I've not been able to beat the built in performance of Array.sort or Array.sortOn functions (unsurprisingly I guess) which I'm sure both use a quicksort, so this is really for you geeks who want to study/play with it. Sort algorithm using divide-and-conquer technique. Array is partitioned into 3 segments, left (west), middle (pivot) and right (east). The pivot segment contains only one element. No element on to the left of the pivot contains a key larger than the pivot, and no element on the right of the pivot contains a key less than the pivot. Now we sort left and right partitions using recursive quick sort. ActionScript Code:
ActionScript Code:
If you linked this up with the Layout class and related classes I posted in this thread(with help from Rampage & senocular)(second large code dump half way down) and added some tweening to the arrange functions: http://<a href="http://www.ultrashoc...adid=66958</a> You could create something along the lines of product sort here: http://www.crew9.net/flash.html |
|
|
2005-04-05
#3 |
||
|
Array Queue
FIFO Queue (simple but worth a post) ActionScript Code:
ActionScript Code:
ActionScript Code:
|
|
|
2005-04-05
#4 |
||
|
Flash Sort
I converted a Java example found at the site bellow and I believe it is correct. From tests the Quick Sort seems WAY faster than the Flash Sort when it comes to an array of strings (at any size), but when it comes to larger arrays (300+) of numbers, FlashSort wins. As the array size increases, so does the performance gap between the two. (Oh, and the name Flash Sort has nothing to do with MM Flash! )Find out more about this sort here: http://www.neubert.net/Flacodes/FLACodes.html ActionScript Code:
ActionScript Code:
|
|
|
2005-06-19
#5 |
||
|
Binary Search (Divide and Conquer)
Last edited by Mike : 2007-04-02 at 11:34.
Updated to use bitwise shift to half and floor m, cheers Nutrox ![]() This may well be floating about Ultrashock somewhere, but I couldn’t find it. Anyway, this is (divide and conquer) binary search on an array sorted in ascending order. This is obviously a lot faster than a sequential search (on average). If you have not come across this before and wish to find out more, you can Google it for loads of result. AS2 Version ActionScript Code:
ActionScript Code:
ActionScript Code:
ActionScript Code:
|
|
|
2006-06-11
#6 |
||
|
Very cool, Mike. Could you maybe create some fictional scenarios where you would specifically pick one of these? I never have the feeling like "hmm, binary search would really speed things up here" (and what about hashtables, splay trees, HOT queues and whatnot?).
|
|
17 Creative Assets
|
2006-06-11
#7 |
||
|
Yar, very nice. I assume, in Layman's terms, that "Data Structures & Algorithms" simply means "utility classes"... unless I've missed something. ![]() Either way, I've made this thread sticky because it looks like it will end up being a good resource. |
|
|
2006-06-11
#8 |
||
|
Cheers Nutrox, They do fall under the umbrella of util classes. Data structures encapsulating a specific collection of data and operations allowed on them. Algorithms providing some sort of working on data structures. Of course there are hundreds more data structures and algorithms out there. I haven't had the need for all of them in Flash just yet. Although it's always good to view the inner workings I think. I hope others feel free to post more (or other versions) so we can build up a nice collection. As for scenarios, well each algorithm has it's own forte. I've posted, along with each algorithm, where and on when it is useful. Data structures I use when I want to hide operations I'm doing on a collection and help clarify my code (for hash table I tend to use a native object as it's pretty much how I would want it). |
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


7 comments
| 2636 views



)
17 Creative Assets
Linear Mode