Cobracrystal
Potet | Cobracrystal | CC
 
 
A particularly inefficient way to sort a given list of integers consists of generating a random permutation of it and check if such permutation contains the elements correctly sorted. That is the so called bogosort algorithm, performing asymptotically (e−1)·n! integer comparisons and (n−1)·n! swaps in average. This kind of algorithm however has several problems. First, it requires a random generator. Then, the best case runtime is very low, just n−1 integer comparisons and no swaps if the given list is already sorted. Finally, the worst case run time is unbounded.
A variation of bogosort that liminates randomness consists of generating all n! permutations of the given list and then search for the one that contains the elements correctly sorted. This keeps the average run time in Ω(n!) integer comparisons, but still produces a low n−1 number of comparison in the best case.
In order to keep the best case run time high, we will change the strategy to find the correctly sorted permutation. Instead of performing a linear search on the list of permutations, we will sort all n! permutations in lexicographical order, and return the first one of them.
The sorting of the list of integer lists can be performed with any standard algorithm such as bubblesort, which runs in Θ(n²) time. The lexicographical order of integer lists is defined so that L1 < L2 precisely when the first index k ∈ [1,...,n] for which they differ verifies L1[k] < L2[k]. So, comparing two integers lists requires at least one integer comparison, and the total time (number of integer comparisons) required to sort n! permutations of n elements in lexicographical order using bubblesort will be Ω((n!)²).
Now, replace bubblesort with another instance of the algorithm just described, i.e., instead of using bubblesort to sort the n! permutations of the original list of n integers, generate the (n!)! permutations of the list of n! permutations, and then sort lexicographically the list of permutations of permutations. The first element will be a list of permutations of integers lists, and the first element of it will be the original list of n integers sorted in increasing order. The number of integer comparisons performed will now be Ω(((n!)!)²).
We finally answer the question of how inefficient a sort algorithm can be.
To do so we define the following sort algorithm, that takes a list of integers L, and an increasing computable function f: ℕ→ℕ as its arguments.
Our algorithm calls multilevelsort(L, k) with the parameters of L and k = f(length(L)).
For k=0, multilevelsort just performs bubblesort on L. For k > 0, multilevelsort performs k recursive selfcalls before using bubblesort. Its run time is Ω(((...(n!)!...!)!)²) = Ω((n)!^(k)).
Therefore, the runtime of worstsort, that takes f, is Ω((n!^(f(n))²), showing that a sort algorithm can be made as inefficient as we wish, with its runtime growing at least as fast as any growing computable function.
Listen to this song and this playlist
현재 오프라인
최근 활동
기록상 54시간
마지막으로 플레이한 날짜: 2024년 9월 24일
기록상 19,881시간
마지막으로 플레이한 날짜: 2024년 9월 24일
기록상 4,555시간
마지막으로 플레이한 날짜: 2024년 9월 21일
Reinners 2024년 8월 3일 오후 7시 15분 
cringe
Chonker 2024년 8월 3일 오후 7시 02분 
╔═══════════════════تَكْبِيرالله☪اللهتَكْبِير ════════════════════╗
If you are a beautiful strong Little PogChamp, someone will put this in your comments.
╚═════════════════لَا إِلٰهَ إِلَّا الله مُحَمَّدٌ رَسُولُ الله══════════════════╝
Reinners 2024년 8월 3일 오후 7시 01분 
This comment is awaiting analysis by our automated content check system. It will be temporarily hidden until we verify that it does not contain harmful content (e.g. links to websites that attempt to steal information).
あくあ-たん 2024년 8월 3일 오후 7시 01분 
╔═══════════════════تَكْبِيرالله☪اللهتَكْبِير ════════════════════╗
If you are a beautiful strong Little PogChamp, someone will put this in your comments.
╚═════════════════لَا إِلٰهَ إِلَّا الله مُحَمَّدٌ رَسُولُ الله══════════════════╝
Cobracrystal 2024년 8월 3일 오후 7시 01분 
person above me is gay
Spoon 2023년 10월 25일 오전 8시 17분 
nice profile pic