HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Sort Algorithms

09-26-2009, 03:44 PM#1
Tot
I need a fast sort algorithm to sort lots of integers.
I've made a demo lib containing Quicksort and Selectionsort (and a new array def, cuz i donno how to give arrays to a func)

Functions


function Quicksort takes Array a returns nothing sorts the complete array via Quicksort


function Selectionsort takes Array a returns nothing Sorts the complete array via Selectionsort




Expand vJass:

the points are:
a) which one is faster
b) are there better ones (with code)
c) what to improve
d) do they work properly

Can't test myself cause we got on strike yesterday evening and I didn't get it working properly (hope the code is without compiling errors)
09-26-2009, 04:40 PM#2
chobibo
I don't fully understand how quicksort works, hence I cannot judge your implementation, but I have to say that quicksort outperforms selection sort with regards to it's average case performance.
09-26-2009, 05:00 PM#3
Tot
Ok, but cause of blizzs strange jass flaws, I thrust a benchmark more than you
(don't be upset, I respect you, but I need to be sure)
09-26-2009, 09:21 PM#4
weaaddar
No numbers really needed. Its avg case N^2 vs avg case n*log(n). Even on the worse input cases for quicksort (an already sorted list), you should be looking at par performance.

As for passable arrays there aren't any, but you can use operators[] or use a global variable to test your sorter.
09-27-2009, 06:08 AM#5
MaD[Lion]
if u wanna sort integers i recommend u look up radix sort, people dont hear about it alot since its application is mostly on sorting numbers, especially integers.
But its performance is totally amazing, ive tried it myself and really loved it. It is comparable to quick/merge sort. it performs at O(kn) worst case, or just O(n) if k is constant.

anyway link: http://en.wikipedia.org/wiki/Radix_sort
09-27-2009, 12:52 PM#6
Tot
@MaD[Lion]:
I don't think that radixsort is working for struct*-integers

(*: jasshelper creates integervalues for structs)
09-27-2009, 07:15 PM#7
PipeDream
I vaguely recall, probably for DARY, that it helped to switch from a recursive n log n sort, either quicksort or mergesort, to an n^2 sort, probably insertion, at around n=10. Helped means quantity of things you could sort before hitting the op limit.
09-29-2009, 07:40 AM#8
MaD[Lion]
tot: u can use radixsort for anything, if ur object/struct has an integer key
Collapse JASS:
struct RadixClass
    integer key
endstruct

//...

struct YourStruct extends RadixClass
...
endstruct