Insertion sort is a basic sorting algorithm that works by iteratively inserting each element of an unsorted list into the appropriate location in a sorted portion of the list. It is a stable sorting method, which means that elements with equal values remain in the same order in the sorted result.
Insertion sort is a basic sorting algorithm that creates a sorted array one element at a time. It is classified as an "in-place" sorting method, which means it requires no additional memory space over the original array.
Insertion sort is used when the number of elements is small. It can also be useful when the input array is nearly sorted, with only a few elements lost in a large array.
This occurs when no sorting is necessary, implying that the array is already sorted. The best-case time complexity for insertion sort is O(n).
This arises when the array elements are jumbled and do not appropriately climb or descend. The average case time complexity for insertion sort is O(n2).
This occurs when array members must be sorted in reverse order. That is, assume you need to sort the array elements in ascending order but the elements are in descending order. The worst-case temporal complexity for insertion sort is O(n2).
The selection sort algorithm's space complexity is O(1).
When the number of elements is small, the insertion sort method is used. It can also be beneficial when the input array is nearly sorted, with only a few elements lost in a large array.