I\'m trying to understand a few sorting algorithms, but I\'m struggling to see the difference in the bubble sort and insertion sort algorithm.
I know both are O(n
Though both the sorts are O(N^2).The hidden constants are much smaller in Insertion sort.Hidden constants refer to the actual number of primitive operations carried out.
When insertion sort has better running time?
Notice that insertion sort is not always better than bubble sort.To get the best of both worlds, you can use insertion sort if array is of small size, and probably merge sort(or quicksort) for larger arrays.