the best-case behavior of insertion sort is o ( n ).
the best-case behavior of insertion sort is o ( n ).
the best-case behavior of insertion sort is ____?
o ( n )
"insertion sort" is a simple sorting algorithm that is relatively efficient for small lists and mostly sorted lists, and is often used as part of more sophisticated algorithms. it works by taking elements from the list one by one and inserting them in their correct position into a new sorted list. in arrays, the new list and the remaining elements can share the array's space, but insertion is expensive, requiring shifting all following elements over by one. shellsort (see below) is a variant of insertion sort that is more efficient for larger lists.









































section::::popular sorting algorithms.:simple sorts.:selection sort.
sorting algorithm
insertion sort is very similar to selection sort. as in selection sort, after "k" passes through the array, the first "k" elements are in sorted order. however, the fundamental difference between the two algorithms is that for selection sort these are the "k" smallest elements of the unsorted input, while in insertion sort they are simply the first "k" elements of the input. the primary advantage of insertion sort over selection sort is that selection sort must always scan all remaining elements to find the absolute smallest element in the unsorted portion of the list, while insertion sort requires only a single comparison when the "k"+1st element is greater than the "k"th element; when this is frequently true (such as if the input array is already sorted or partially sorted), insertion sort is distinctly more efficient compared to selection sort. on average (assuming the rank of the "k"+1st element rank is random), insertion sort will require comparing and shifting half of the previous "k" elements, meaning insertion sort will perform about half as many comparisons as selection sort on average. in the worst case for insertion sort (when the input array is reverse-sorted), insertion sort performs just as many comparisons as selection sort. however, a disadvantage of insertion sort over selection sort is that it requires more writes due to the fact that, on each iteration, inserting the "k"+1st element into the sorted portion of the array requires many element swaps to shift all of the following elements, while only a single swap is required for each iteration of selection sort. in general, insertion sort will write to the array o("n") times, whereas selection sort will write only o() times. for this reason selection sort may be preferable in cases where writing to memory is significantly more expensive than reading, such as with eeprom or flash memory.
insertion sort