A simple implementation of the BogoSort (permutation sort) algorithm in Java.
BogoSort repeatedly shuffles the array randomly until it happens to be sorted. It is one of the most inefficient sorting algorithms and is mainly used for educational purposes.
- Check if the array is sorted.
- If sorted, print the result and stop.
- If not, randomly shuffle the array using Fisher-Yates shuffle.
- Repeat from step 1.
| Case | Complexity |
|---|---|
| Best | O(n) |
| Average | O(n * n!) |
| Worst | O(∞) |
Compile and run:
javac src/BogoSort.java
java -cp src BogoSort