We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 27d53fb commit 18b9ce1Copy full SHA for 18b9ce1
algorithms/sort/bogo_sort.py
@@ -1,11 +1,16 @@
1
import random
2
3
-def bogo_sort(arr):
+def bogo_sort(arr, simulation=False):
4
"""Bogo Sort
5
Best Case Complexity: O(n)
6
Worst Case Complexity: O(∞)
7
Average Case Complexity: O(n(n-1)!)
8
"""
9
+
10
+ iteration = 0
11
+ if simulation:
12
+ print("iteration",iteration,":",*arr)
13
14
def is_sorted(arr):
15
#check the array is inorder
16
i = 0
@@ -14,9 +19,14 @@ def is_sorted(arr):
19
if arr[i] > arr[i+1]:
20
return False
21
i += 1
22
23
17
24
return True
18
25
while not is_sorted(arr):
26
random.shuffle(arr)
27
28
29
+ iteration = iteration + 1
30
31
32
return arr
-
0 commit comments