Skip to content

Commit

Permalink
added simulation to bogo_sort.py (keon#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwoogit authored and goswami-rahul committed Jun 14, 2018
1 parent 27d53fb commit 18b9ce1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions algorithms/sort/bogo_sort.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import random

def bogo_sort(arr):
def bogo_sort(arr, simulation=False):
"""Bogo Sort
Best Case Complexity: O(n)
Worst Case Complexity: O(∞)
Average Case Complexity: O(n(n-1)!)
"""

iteration = 0
if simulation:
print("iteration",iteration,":",*arr)

def is_sorted(arr):
#check the array is inorder
i = 0
Expand All @@ -14,9 +19,14 @@ def is_sorted(arr):
if arr[i] > arr[i+1]:
return False
i += 1


return True
while not is_sorted(arr):
random.shuffle(arr)

if simulation:
iteration = iteration + 1
print("iteration",iteration,":",*arr)

return arr


0 comments on commit 18b9ce1

Please sign in to comment.