Insertion Sort Algorithm and Complexity Analysis
Insertion Sort Algorithm and Complexity Analysis
The time complexity of insertion sort is O(n^2), where "Insertion sort is efficient for sorting
n is the number of elements in the array. small arrays or arrays that are
In the worst case, when the input array is in reverse
already partially sorted."
order, the time complexity of insertion sort is
maximum.
Summary
"The time complexity of insertion
sort is O(n^2), where n is the Insertion sort is a simple, in-place sorting algorithm
number of elements in the array." that builds the final sorted array one item at a time.
It has a time complexity of O(n^2) and a space
complexity of O(1).
Space Complexity of Insertion Insertion sort is stable and adaptive, making it
suitable for partially sorted data.
Sort It is commonly used for sorting small arrays or as the
final step in more complex sorting algorithms.
The space complexity of insertion sort is O(1)
because it only requires a constant amount of "Insertion sort is a simple, in-place
additional space.
Insertion sort performs sorting in-place, meaning it
sorting algorithm that builds the final
does not require any additional data structures. sorted array one item at a time."