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

后端 未结 4 1239
小蘑菇
小蘑菇 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:04

    According to the java jvm 8 javadocs of Arrays.sort() method:

    The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.

    So it will increase your time complexity from O(n) to O(n log(n))

提交回复
热议问题