Will Arrays.sort() increase time complexity and space time complexity?

后端 未结 4 1228
小蘑菇
小蘑菇 2020-12-08 08:44

There is an array related problem, the requirement is that time complexity is O(n) and space complexity is O(1).

If I use Arrays.sort(arr), and use a

4条回答
  •  粉色の甜心
    2020-12-08 09:12

    Arrays.sort(int[] a) in recent JDK is implemented with Dual-pivot Quicksort algorithm which has O(n log n) average complexity and is performed in-place (e.g. requires no extra space).

提交回复
热议问题