Looking at the code of insertion sort we can see that we require one comparison for all ‘n’ elements initially. (yes for the first element we don’t need this, but let us ignore it.). Therefore ‘n’ comparisons.
Then for each swap(= number of inversions, let it be ‘d’), there will be one comparison each to check whether we need to swap or not. Therefore ‘d’ more comparisons.
Obviously ‘d’ swaps for ‘d’ inversions. Therefore O(n+d+d) = O(n+d).
Here d=n, therefore O(n).