Bogosort Overview:
The Bogosort sorting algorithm functions by checking if a list is ordered, and if it isn't randomizing the order
of the elements inside
until the list is sorted.
- Check if list is ordered, if so return ordered list
- Randomize list
- Repeat
Diagram:
Algorithm Example:
Assuming the starting array is as follows
A possible sorting of this array into descending order by Bogosort may look like this:
- 1st Iteration: Check if {3, 4, 5} is sorted. No, so randomize: new array: {4, 3, 5}
- 2nd Iteration: Check if {4, 3, 5} is sorted. No, so randomize: new array: {5, 4, 3}
- 3rd Iteration: Check if {5, 4, 3} is sorted. Yes, so sorted array is {5, 4, 3}
More information!