
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program for BogoSort or Permutation Sort
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given an array, we need to sort it using the concept of permutation sort.
BogoSort also is known as permutation sort, is based on generating and testing paradigms.
Now let’s observe the solution in the implementation below−
Example
# random module import random # Sort def bogoSort(a): n = len(a) while (is_sorted(a)== False): shuffle(a) # check def is_sorted(a): n = len(a) for i in range(0, n-1): if (a[i] > a[i+1] ): return False return True # permutation def shuffle(a): n = len(a) for i in range (0,n): r = random.randint(0,n-1) a[i], a[r] = a[r], a[i] # main a = [1,5,3,4,8,6,3,4,5] bogoSort(a) print("Sorted array :") for i in range(len(a)): print (a[i],end=" ")
Output
Sorted array is : 1 3 3 4 4 5 5 6 8
All the variables are declared in the local scope and their references are seen in the figure above.
Conclusion
In this article, we have learned about how we can make a Python Program for BogoSort or Permutation Sort
- Related Articles
- C++ Program for BogoSort or Permutation Sort?
- C++ Program for the BogoSort or Permutation Sort?
- Python Program for Bubble Sort
- Python Program for Insertion Sort
- Python Program for Selection Sort
- Python Program for Cocktail Sort
- Python Program for Counting Sort
- Python Program for Cycle Sort
- Python Program for Gnome Sort
- Python Program for Heap Sort
- Python Program for Merge Sort
- Python Program for Stooge Sort
- Python Program for Odd-Even Sort / Brick Sort
- Python Program for Binary Insertion Sort
- Python Program for Iterative Merge Sort

Advertisements