Question: Implement the following two sorting algorithms in a program called p3.py. Write two separate functions for these algorithms. Both functions must take a list

Implement the following two sorting algorithms in a program called p3.py. Write two separate functions for

Implement the following two sorting algorithms in a program called p3.py. Write two separate functions for these algorithms. Both functions must take a list of integers as the input parameter. You must NOT use the built-in methods for shuffling the list elements or sorting a list. 1) Bogosort: first shuffle the elements in the list (i.e., randomize the positions of every element) and check if the resulting list is sorted. If it is, the algorithm terminates successfully by returning True. Otherwise, the process must be repeated. 2) Bozosort: choose two elements in the list at random, swap them, and then check if the resulting list is sorted. If it is, the algorithm terminates successfully returning True. Otherwise, the process must be repeated. Write a main() function and call both sorting functions using the same list argument. The list can be of any size (but try a small list of 3 integers first). Do any of your algorithms terminate? If yes, count the number of iterations it uses to sort the list. Does it always use the same number of repetitions? If not, why? You can discuss with the TAs and your peers.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python Keep in mind that both Bogosort and Bozosort are not pra... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!