Sorting algorithm | Array.sort () algorithm rules

1, js the Array.sort () is what sort algorithm;

1, Firefox is " merge sort "

2, V8 engine is the " insertion sort and quicksort combination ." When the array length not more than 10, using an insertion sort. Longer than 10 using a fast sort. Insertion sort is more efficient in the short array.

 

 

Algorithm complexity:
best case: O (nlogn)
worst case: O (nlogn)
Average case: O (nlogn) merge sort need to do a secondary sort the array of the same length of the original array
space complexity: O (n)
stability: stable (stable sort merge sort algorithm, temp[i++] = arr[p1] <= arr[p2] ? arr[p1++] : arr[p2++];which ensures that when the line equal to the value when the left and right parts, to copy the value of the left, so that the relative position ensures that when the two values are equal to the same elements. )

 

Selection sort, bubble, insertion, fast,

 

Guess you like

Origin www.cnblogs.com/liujinyu/p/11831464.html