Time Complexity
best O(n)
Worst O(n^2)
Average O(n^2)
Space Complexity
O(1) - because only use one temp variable
BigOh
O(n^2)
Opinion
If the array is already sorted this algorithm just loop O(n), but the performance of this algorithm is too variable.
(I don't put the code or concept because for practice)
https://www.programiz.com/dsa/insertion-sort
Top comments (0)