Java Is sorting () called by an already sorted list of O (1) called?

Does it check whether O (1) is Collections.sort(list)sorted listor maybe for some other reason?
Or is it a good idea to sort the flag and set it to true/ falseafter calling sort()/ adding an item to the list?

+5
source share
4 answers

How can you tell if a list is sorted without looking at it? It will not be O(1). The definition of sorting the list takes at least O(n).

This would mean that if you Collections.sortbothered to check whether the list was sorted, first each sort operation takes an average value O(n) + O(n log n).

+9
source

O (1), , , O (n). , , , .

+3

( , ). .

Collections.sort() .

+2

Java7, Java mergesort TimSort ( python dev , cpython first) .

While this is not O (1), sorting an already sorted or partially sorted list with TimSort is quite efficient than sorting a completely random dataset (for a later time, there is no way to be more efficient than O(n log n)comparing sorting, which is not true for non-random data).

+2
source