Statistics
Controls
Summary
Bozo Sort is another member of the "perversely awful" family of randomized sorting algorithms. It operates on a simple principle: if the array isn't sorted, make a minimal random change and hope for the best. Specifically, it randomly selects two elements and swaps them. This process is repeated until the array happens to be in sorted order. While conceptually similar to Bogo Sort (which shuffles the entire list), Bozo Sort's incremental random changes make its path to a solution even more meandering and unpredictable. It serves as a powerful educational example of brute-force, randomized approaches and why they are impractical for real-world use.
How it Works
-
1. Check Order: Iterate through the list to check if it is sorted. If it is, the algorithm terminates successfully.
-
2. Select Pair: If the list is not sorted, randomly select two indices,
index1andindex2. These indices can be the same. -
3. Swap: Swap the elements at
arr[index1]andarr[index2]. -
4. Repeat: Go back to step 1 and repeat the process until the sorted order is achieved by chance.