How would you describe the running time of this sort, given a function sorted which returns True if the list is sorted that runs in O(n):
def sort(l): while not sorted(l): random.shuffle(l)
Assume shuffling is perfectly random.
Would this be written in big-O notation? Or is there some other way of categorizing algorithms with random components?
This Algorithm is called Bogosort. It is an instance of a class of Algorithms called Las Vegas Algorithms. Las Vegas Algorithms are Randomized Algorithms which always guarantee correct results but make no guarantees about the computing resources.
The time-complexity of Bogosort cannot directly be expressed in Bachmann-Landau Notation, because of its probabilistic nature. However, we can make a statement about its expected time-complexity. The expected time-complexity of Bogosort is
O(n·n!).