algorithm - What should be the ideal threshold on array size in order to use a non-recursive sorting method? -


i did revision on sorting algorithms. while revisioning, imagined code selects optimal of 2 available sorting algorithms sort array, according array's size. example, has choose between insertion sort , quicksort.

it's known quicksort used extensively sort large arrays , achieves average case time, o(nlogn), although worst-case time o(n^2). on other hand, insertion sort isn't recursive, may consume less cpu time when sorts small-sized array. so, should nice threshold size aforementioned code in order choose efficient of algorithms?

other performance factors, "how close" given sequence sorted permutation, aren't concerning me right now.

from princeton university's quicksort page

cutoff insertion sort. mergesort, pays switch insertion sort tiny arrays. optimum value of cutoff system-dependent, value between 5 , 15 work in situations.

i prefer cut off size of 15. again system dependent , may or may not best in case.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -