AlgoViz

Overview

Bogo Sort is a highly inefficient sorting algorithm based on the generate-and-test paradigm. It repeatedly shuffles the array randomly until it finds a sorted arrangement.

Time Complexity:
Best case: O(n) - When the array is already sorted (highly unlikely)
Average case: O((n+1)!) - The expected number of permutations is factorial in size
Worst case: Unbounded - It can theoretically run forever if unlucky with shuffles
Space Complexity: O(1) - It is an in-place sorting algorithm.

No. of comparisons: 0 No. of swaps: 0
while not isSorted(list)
  shuffle(list)
SHORT EXPLANATION
------------------
1. Check if the list is sorted.
   - If the list is sorted, the algorithm is complete.
2. If the list is not sorted, shuffle the entire list randomly.
3. Repeat the process until the list becomes sorted.
4. Since shuffling is random, this sort can take an unpredictable amount of time.
50 1000
5 50
arrow_upward