Program for Bogo Sort using Python


Bogo sort is based on generate and test paradigm and is also known as Permutation sort, shotgun sort or monkey sort. Our task is to sort the given array elements using bogo sort. It ineffective sorting algorithm.


import random
def sort(arr):
    length = len(arr)
    while (sorted_ele(arr) == False):
def sorted_ele(arr):
    length = len(arr)
    for i in range(0, length - 1):
        if (arr[i] > arr[i + 1]):
            return False
    return True
def shuffle_ele(arr):
    length = len(arr)
    for i in range(length):
        r = random.randint(0, length-1)
        arr[i], arr[r] = arr[r], arr[i]
ip_arr = [10, 2, 51, 3]
print("The sorted array is: ")
for i in range(0, len(ip_arr)):


Program for Bogo Sort using Python


In the above program, we have select one element from array and randomly place it at position. This process of sorting continues until all the items within the array is sorted.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.