Implement the following two sorting algorithms in a program called p3.py. Write two separate functions for...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Python Keep in mind that both Bogosort and Bozosort are not pra... View the full answer
Related Book For
Principles Of Information Security
ISBN: 9780357506431
7th Edition
Authors: Michael E. Whitman, Herbert J. Mattord
Posted Date:
Students also viewed these programming questions
-
The site http://virtualpiano.net features an online player piano. If you click on the Key Assist menu just above the piano keyboard, and then Keyboard Keys, you will see that each key is labelled...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Bike World, Inc., wholesales a line of custom road bikes. Bike World's inventory, as of November 30, 2016, consisted of 22 mountain bikes costing $1,650 each. Bike World's trial balance as of...
-
Certain streets in San Francisco make an angle of 17.5 with the horizontal. What force parallel to the street surface is required to keep a loaded 1967 Corvette of mass 1390 kg from rolling down such...
-
What is H.263?
-
Consider the calculation of an external rate of return (ERR). The positive cash flows in the cash flow profile are moved forward to \(t=n\) using what value of \(i\) in the \((F \mid P i, n-t)\)...
-
The outstanding capital stock of Pennington Corporation consists of 2,000 shares of $100 par value, 6% preferred, and 5,000 shares of $50 par value common. Assuming that the company has retained...
-
20. a) Choose an algebraic method to solve the following linear system. Explain why you chose this method. 2 3x 2 2y 3 7 3 + 2y = 5 b) Use the method you chose to solve the system. Check your...
-
3. (3 points) Does a function with these characteristics exist? If yes, draw a graph of such a function. Label the important points on the graph or 2-axis. If no, explain why not. A function g has...
-
What type of information is provided by each type of statement?
-
Debate the impact of digital technology on the way we live, work and enjoy ourselves by focusing on freedoms and limitations.
-
Does the cash budget require an extensive knowledge of accounting principles?
-
Explore the options, success factors and barriers to delivering artificial intelligence and Big Data applications for marketing.
-
Explain how digital channels have altered how companies can differentiate their brands online.
-
Fill in the blanks: S. No. Cost Price Selling Price Profit Loss (a) $ 2400 $ 400 (b) $ 1900 $ 300 (c) S 2900 S 100 (d) $ 1590 $ 60 (e) $ 4100 S 300 (f) S 1200 $ 180 (g) $ 1450 S 45 (h) $ 5900 $ 490
-
The senior management at Davis Watercraft would like to determine if it is possible to improve firm profitability by changing their existing product mix. Currently, the product mix is determined by...
-
Explain that this threat represents a well-known and broad category of electronic and human activities that breach the confidentiality of information. Establish that when an unauthorized individual...
-
Compare and contrast the different positions that are part of an implementation for an information security program. The Chief Information Officer (CIO) is the senior technology officer of an...
-
I. Summarize knowledge that individuals who are not subject to rigorous screening, contractual obligations, and eventual secured termination often have access to sensitive organizational information....
-
Salen Company finances some of its current operations by assigning accounts receivable to a finance company. On July 1, 2015, it assigned, under guarantee, specific accounts amounting to 150,000,000....
-
Bill Jovi is reviewing the cash accounting for Nottleman, Inc., a local mailing service. Jovis review will focus on the petty cash account and the bank reconciliation for the month ended May 31,...
-
On October 1, 2015, Arden Farm Equipment Company sold a pecan-harvesting machine to Valco Brothers Farm, Inc. In lieu of a cash payment Valco Brothers Farm gave Arden a 2-year, $120,000, 8% note (a...
Study smarter with the SolutionInn App