+ 16
when do you choose mergesort in java? when do you choose insertion sort?
I guess I'm looking for examples for these 2 sort types.selection sort seems pretty straightforward. Thanks for any help.
2 Antworten
+ 12
Insertion sort should be used when there are only few items to sort.
Internally Java uses insertion sort to sort arrays of primitives with up to 6 values and switches to merge sort for up to 13 values (I hope I remember this correctly).
See this for comparison of the algorithm according to values / sorting time and code examples:
http://www.titrias.com/sorting-algorithms-comparison-insertion-sort-vs-merge-sort/
+ 4
InsertionSort is slowly because it is check the value one by one. mergeSort is better than insert.