insertion sort worst time complexity for near sorted array?

I have an n-element array. All elements except 4√n of them are sorted. We do not know the positions of these misplaced elements. What is the most efficient way of sorting this list?

Is there an O(n) way to do this?

Update 1:

time complexity of an​ insertion sort is O(n) for almost sorted data (is it true in worst case?)?



Read more here: https://stackoverflow.com/questions/64956096/insertion-sort-worst-time-complexity-for-near-sorted-array

Content Attribution

This content was originally published by Davied Zuhraph at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: