Insertion Sort, Algorithms, Data Structure Algorithm, Coding Interviews, Job Hunting.
of n size, the algorithm performs n-1 passes. And the total no. of comparisons would be 1 + 2 + 3…(n-1) = n(n-1)/2 = O(n2) Best case complexity: The best case of insertion sort will be when we have a sorted array. Suppose we have an array as 1 2 3 4 5. In this case, we will compare 2 with 1, no