What is this odd sorting algorithm?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Sorting algorithms are a foundational concept in computer science, allowing for the efficient organization of data. While classic sorting algorithms such as QuickSort, MergeSort, and BubbleSort are well-documented, an intriguing category of sorting algorithms often referred to as "odd sorting algorithms" provides unique methods of sorting with unconventional approaches. These algorithms, while not always the most efficient for general use, bring creative insights into problem-solving and algorithm design.
Odd Sorting Algorithm Explained
Odd sorting algorithms, as the name suggests, often use peculiar methods to sort data. One such algorithm is the BogoSort, also known as "stupid sort" or "monkey sort," which relies on generating random permutations of the input array until it finds a sorted order. While it is easy to implement, its expected time complexity is notably poor, often categorically classified as , where is the number of elements.
Example: BogoSort
- Algorithm Steps: • Randomly shuffle or permute the array. • Check if the array is sorted. • If not sorted, repeat the above steps.
- Implementation in Python:• Time Complexity: (average case); in the worst case, it may never terminate on a non-finite number of steps. • Space Complexity: , as it sorts in place. • Understanding Efficiency: They highlight the importance of algorithm efficiency and contrast with more optimal methods. • Algorithm Design: Creative processes involved in these unconventional methods can inspire innovative approaches in other computational problems. • Educational Value: Serving as excellent educational tools, they can help beginners understand fundamental concepts of randomness, probability, and permutation. • Utilizes system sleep functions to "sort" numbers implicitly by time delays proportional to element values. • Highly inefficient for practical use and cannot handle negative or non-integer numbers. • A variant of BogoSort that is even less efficient. It recursively checks sorted subarrays, with complexities exploding even faster than BogoSort. • Another humorous algorithm that recursively sorts the first two-thirds of an array, then the last two-thirds, and the first two-thirds again. • Has a time complexity of , which is approximately .
Related reading
- What is wrong with this algorithm execution in Java?
- What is Youtube comment system sorting / ranking algorithm?
- What kind of algorithm is behind the Akinator game?
- What kind of algorithm is behind the Akinator game?
- What language was RabbitMQ written in?
- What makes this a fixed-length list in Dart?
- What machine learning algorithm for this simple optimisation?
- What major problems would I have if I use Raft Consensus Algorithm in 50+ pods?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.