Question

So I know the O(N) for linear is n, insertion is n**2, binary is log(n) and merge is nlogn

So Merge Sort is the best search for large lists. Which of the above is the best for small lists i.e. how small? Thanks

No correct solution

OTHER TIPS

You're mixing up sort and search algorithms. Linear search and binary search are algorithms for finding a value in an array, not sorting the array. Insertion sort and mergesort are sorting algorithms.

Insertion sort tends run faster for small arrays. Many high-performance sorting routines, including Python's adaptive mergesort, automatically switch to insertion sort for small input sizes. The best size for the switch to occur is generally determined by testing. Java uses insertion sort for <= 6 elements in the primitive array versions of Arrays.sort; I'm not sure exactly how Python behaves.

You have got your facts wrong,

There is nothing called Linear Sort.

Insertion Sort is O(N^2)

There is nothing called Binary Sort

Though it could be Heap Sort which is O(NlogN)

MergeSort is O(NlogN)

QuickSoty is O(NlogN)

It is better to switch to insertion sort from merge sort if number of elements is less than 7

It is better to switch to insertion sort from quick sort if number of elements is less than 13

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top