Comparison of several sorting algorithms: Arrays

(Main test page)

In this test each item was an array of 50 integers (iow. 200 bytes). Only the first integer was used for comparison. Thus in this test comparison is very fast but copying is slow.

The array of 1 million items was skipped because it was extremely slow to test.

In order to better compare the results with the previous strings test, both charts are shown in each case (strings test first, array test below it).

100 items

100 arrays

100 arrays

Insertion sort is not as much penalized as with the strings case, but still somewhat. Insertion sort probably makes more comparisons than copying (in relation to the comparisons/copying ratio of the other algorithms).

Except for the vanilla quicksort, all the others seem to behave very similarly to the strings test.

Random Almost sortd Almost rev. Random end
Alg.Comp.Assig. Comp.Assig. Comp.Assig. Comp.Assig.
Insert. 25672670 418517 47044827 25672670
Shell 7671076 463747 7311092 7671076
Heap 10271743 10691882 9571558 10271743
Merge 558800 470800 424800 558800
Quick 1062475 2809241 2052335 1062475
Quick2 783724 691393 599487 783724

5000 items

5000 arrays

5000 arrays

A notable difference compared to the previous strings test can be seen with the vanilla quicksort, which in this case doesn't show signs of difficulty. Also merge sort seems surprisingly slower to the others in the arrays test.

Random Almost sortd Almost rev. Random end
Alg.Comp.Assig. Comp.Assig. Comp.Assig. Comp.Assig.
Shell 101380136567 76338109893 81473118792 67960101361
Heap 107688171316 109624177665 103760161278 111987181247
Merge 5682470000 5172170000 5146170000 3461070000
Quick 9529842894 33612322098 21544931199 103409127139
Quick2 7428156372 8100632104 8105938236 13080433511

100000 items

5000 arrays

5000 arrays

Again, quicksort handles this case better (except for the expected "random end" pathological case) for some reason. The optimized quicksort and even std::sort show the same problematic trend with the "random end" case, although slightly less pronouncedly.

Random Almost sortd Almost rev. Random end
Alg.Comp.Assig. Comp.Assig. Comp.Assig. Comp.Assig.
Shell 38959214892488 28833763843683 29287663956272 16446432600399
Heap 30195964724828 30248254792736 29379034519024 31323324973720
Merge 15664951800000 14647971800000 14635881800000 8793221800000
Quick 25519841153577 9853078577498 6044543848086 --
Quick2 20222651432913 2145137772913 2191912906267 4813088554475

Conclusion

Shell sort seems to be again just slightly better than heap sort.

A bit surprisingly the vanilla quicksort handles this case much better than the strings case.

Merge sort clearly loses its edge when copying is slow. The compare/copying ratio of merge sort seems to put it at an disadvantage compared to when comparison is slow and copying fast.


Previous - Conclusion