1. Write bubble_sort(a) function to execute bubble sort algorithm, which is a simple sorting algorithm that...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Write bubble_sort(a) function to execute bubble sort algorithm, which is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements and swaps them if they are in the wrong order, until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list. (10 marks) 2. Write optimized_bubble_sort(a) function which is an optimized version bubble sort algorithm that reduce the number of swaps and comparisons. (10 marks) 3. Write generate_unsorted_list(n) function which generates random unsorted list (an array) with 10,000 elements to test above mentioned algorithms. (5 marks) 4. Write code to calculate: (i) The Execution time for each algorithm, (ii) The saved execution time using optimized bubble sort algorithm in comparison to the bubble sort algorithm. (5 marks) For example, executing your entire program should return the following: Bubble Sort Algorithm execution time = 8.794462203979492 seconds. Optimized Bubble Sort Algorithm execution time = 0.0011148452758789062 seconds. Execution time saved using Optimized Bubble Sort Algorithm = 8.793347358703613 seconds. Hint: you can use the random integer "randint" and "time" modules in your solution 1. Write bubble_sort(a) function to execute bubble sort algorithm, which is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements and swaps them if they are in the wrong order, until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list. (10 marks) 2. Write optimized_bubble_sort(a) function which is an optimized version bubble sort algorithm that reduce the number of swaps and comparisons. (10 marks) 3. Write generate_unsorted_list(n) function which generates random unsorted list (an array) with 10,000 elements to test above mentioned algorithms. (5 marks) 4. Write code to calculate: (i) The Execution time for each algorithm, (ii) The saved execution time using optimized bubble sort algorithm in comparison to the bubble sort algorithm. (5 marks) For example, executing your entire program should return the following: Bubble Sort Algorithm execution time = 8.794462203979492 seconds. Optimized Bubble Sort Algorithm execution time = 0.0011148452758789062 seconds. Execution time saved using Optimized Bubble Sort Algorithm = 8.793347358703613 seconds. Hint: you can use the random integer "randint" and "time" modules in your solution
Expert Answer:
Answer rating: 100% (QA)
import random import time Bubble Sort Algorithm def bubblesorta n lena for i in rangen for j in rang... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these algorithms questions
-
3. a)Calculate the momentum of a 5.0 kg mass with a kinetic energy of 3.0 x 10 J b) How fast is the mass moving?
-
Read the case study "Southwest Airlines," found in Part 2 of your textbook. Review the "Guide to Case Analysis" found on pp. CA1 - CA11 of your textbook. (This guide follows the last case in the...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Identify the implied strategies that correspond with the Department of Veterans Affairs Healthcare System High Matrix Score on SWOT quadran that they might look like at your HSO. Also explain why...
-
McCormick Optical Company reported the following amounts on its balance sheet at December 31: Cash and receivables ......................................................................................
-
For each of the following data sets, formulate the mathematical model that minimizes the largest deviation between the data and the line y = ax+b. If a computer is available, solve for the estimates...
-
Select five of these alleged fraudsters and prepare a two-paragraph discussion of them. Outline their modus operandi. 1. Frank Abagnale 2. Jack Abramoff 3. Kobi Alexander 4. Eddie Antar 5. Jim Bakker...
-
Part proliferation: role for activity-based costing An article in the Wall Street Journal by Neal Templin and Joseph B. White (June 23, 1993) reported on the major changes occurring at General...
-
help, im really confused with this. 2. Question 2 [Total: 20 marks] a) Suppose that on October 24, 2020, a company sells one April 2021 live-cattle futures contract. It closes out its position on...
-
Jake claims that he can buy a $210,000 for about the same as his rent, and therefore he should definitely buy because he has heard that "renting is bad". Help him walk through this argument. a....
-
According to exchange between John Smith and Powhatan What goods does each seek from the other?
-
Driver error can be listed as the cause of approximately 54% of all fatal auto accidents, according to the American Automobile Association. Thirty randomly selected fatal accidents are examined, and...
-
According to the Center for Disease Control website, in 2011 at least 18% of high school students have smoked a cigarette. An Introduction to Statistics class in Davies County, KY conducted a...
-
A statistics instructor believes that fewer than 20% of Evergreen Valley College (EVC) students attended the opening night midnight showing of the latest Harry Potter movie. She surveys 84 of her...
-
A survey in the N.Y. Times Almanac finds the mean commute time (one way) is 25.4 minutes for the 15 largest US cities. The Austin, TX chamber of commerce feels that Austins commute time is less and...
-
The student academic group on a college campus claims that freshman students study at least 2.5 hours per day, on average. One Introduction to Statistics class was skeptical. The class took a random...
-
Cul es el principal uso de los Spreads como estrategia de inversin? (Respuesta en un prrafo bien estructurado) Cul estrategia de inversin de opciones usted utilizara?, Por qu? (Respuesta en dos...
-
Assume Eq. 6-14 gives the drag force on a pilot plus ejection seat just after they are ejected from a plane traveling horizontally at 1300 km/h. Assume also that the mass of the seat is equal to the...
-
Modify the proto-vEB structure to support duplicate keys.
-
Suppose that instead of superimposing a tree of degree u, we were to superimpose a tree of degree u 1/k , where k > 1 is a constant. What would be the height of such a tree, and how long would each...
-
The P-MATRIX-MULTIPLY-RECURSIVE procedure has the disadvantage that it must allocate a temporary matrix T of size n n, which can adversely affect the constants hidden by the -notation. The...
-
Determine which of -38 and 27 is larger using a number line, and express that using both the greater than and the less than notations.
-
Graph the following numbers on the number line: 1. -10 2. 4 3. 0
-
Use your calculator to calculate 38 - 100. Explain how the answer agrees with what was expected.
Study smarter with the SolutionInn App