ziyistudy's blog

By ziyistudy, history, 10 months ago, In English

A. SwapSort

it's a quite easy problem within n<=1000. But I am wondering can we solve the problem in O(n), I have seen some people mention about it.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

The process of performing swaps via a cycle detection method can indeed be done in O(n). However, determining the sorted order using a general comparison-based algorithm will typically be O(nlogn) only ig. Therefore, unless you make additional assumptions (e.g., a limited range of values), the overall algorithm will be dominated by the sorting phase (O(nlogn)) rather than the swap phase (O(n)).

So ig nlogn