Does the Collections.sort(list) check if the list is already sorted or is it maybe O(1) for some other reason?
Or, is it a good idea to have a flag sorted and set it to true/false upon calling sort()/adding an element to the list?
Does the Collections.sort(list) check if the list is already sorted or is it maybe
Share
How can you determine if any list is sorted without looking at it? It wont be
O(1). Determining if a list is sorted takes at leastO(n).That would mean If
Collections.sortdid bother to check if a list was sorted first each sorting operation would take an average ofO(n) + O(n log n).