algorithm - Why is merge sort considered to be best -


why not insertion sort binary insert considered best ?

merge sort : t(n) = n + 2*t(n/2) = o(n*log(n))   insertion sort binary insert : t(n) = log(n-1) + t(n-1) = o(log(n!))   , n^n > n! ; n*log(n) > log(n!) 

for bigger n, improve performance.

or missing ?

forgive me if asking trivial question, new programming , want facts right.

i think estimation of insertion sort's complexity wrong. didn't describe details of how got result, seems forgot time needed insert - mean time need move part of sorted array make place element inserting.

after sorted n-1 elements, need o(log(n)) time find place n-th element , o(n) (pessimistically) time move part of sorted array , make place n-th element. total complexity

o(1 + ... + n + log 1 + ... + log n) = o(n^2 + n log n) = o(n^2).

you don't improve algorithm binary search, because have shift part of array (of linear size in terms of n) anyway.


Comments