logo CodeStepByStep logo

bogo_sort

Language/Type: Python lists collections
Related Links:

Write a function named bogo_sort that sorts a list of numbers in a "bogus" or silly way by repeatedly shuffling the list until it happens to get lucky and shuffles the list into sorted order. The pseudocode for the bogo sort algorithm is the following:

while list is not sorted:
    shuffle list.

You may assume the presence of a pre-existing function is_sorted that accepts a list as its parameter and returns True if the list's elements are in sorted non-decreasing order, and False if not.

(Due to limitations of our site, we are unable to actually check whether you follow the bogo algorithm described above. We will check that your algorithm sorts properly, but it is up to you or your TA/instructor to verify that you followed the algorithm specified.)

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.