FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms-python/algorithms/sort/bogo_sort.py at master · ivan1911/algorithms-python · GitHub
ivan1911
/
algorithms-python
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms-python
/
algorithms
/
sort
/
bogo_sort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (25 loc) · 740 Bytes
Breadcrumbs
algorithms-python
/
algorithms
/
sort
/
bogo_sort.py
Copy path
File metadata and controls
32 lines (25 loc) · 740 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
random
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
arr_len
=
len
(
arr
)
while
i
+
1
<
arr_len
:
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
Back
|
FazBrowse Home
|
New Git URL