fficiency of Algorithms 170 of 930 11. For each of the following lists, perform a bubble...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
fficiency of Algorithms 170 of 930 11. For each of the following lists, perform a bubble sort, and show the list after each exchange. Compare the number of exchanges done here and in the Practice Problem at the end of Section 3.3.3. a. 4, 8, 2,6 b. 12,3, 6, 8, 2, 5, 7 c. D, B, G, F, A, C, E, H 12. Explain why the bubble sort algorithm does (n) comparisons on an n-element list. 13. Suppose selection sort and bubble sort are both performed on a list that is already sorted. Does bubble sort do fewer exchanges than selection sort? Explain. 14. Bubble sort can be improved. Smart bubble sort keeps track of how many exchanges are done within any single pass through the unsorted section of the list. If no exchanges occur, then the list is sorted and the algorithm should stop. a. Write a pseudocode version of the smart bubble sort algorithm. b. Perform a smart bubble sort on the following list. How many comparisons are required? 7, 4, 12, 9, 11 c. Describe the best-case scenario for smart bubble sort on an n-element list. How many comparisons are required? How many exchanges are required? d. Under what circumstances does smart bubble sort do the same number of comparisons as regular bubble sort? 3. Split the list into two halves Sort the first half of the list using mergesort 4. 5. Sort the second half of the list using mergesort 6. Merge the two sorted halves A and B into a new sorted list C by comparing the next two items from A and B and always choosing the smaller value to go into C 7. Stop Mergesort works by using the result of mergesort on two smaller lists, so mergesort, like the Fibonacci sequence in Exercise 3, is a recursive algorithm. Step 6 in this algorithm deserves an example. Suppose that at one point in running mergesort we have two sorted lists A and B, as follows: A = 2,9 B = 6,7 To create C, we compare 2 from A and 6 from B. Because 2 is smaller, it is removed from A and goes into C. A = 9 B= 6,7 C=2 Now compare 9 from A and 6 from B. Because 6 is smaller, it is removed from B and goes into C. A=9 B=7 C = 2,6 Comparing 9 and 7 results in A = 9 B = C = 2,6,7 Finally, let us agree to count comparing 9 to nothing as a legitimate, if trivial, comparison resulting in 9, which is added to C, the final sorted list. A = B = Exercises 15-17 refer to still another sorting algorithm, called mergesort. Mergesort breaks the list to be sorted into smaller and smaller lists until there is just a bunch of one-element (and thus obviously sorted) lists, then assembles the smaller sorted lists back together into larger and larger sorted lists. Here is a pseudocode version: 1. Get values for n and the n list items 2. While the current list has more than 1 item, do Steps 3 through go Learning. All Rights Reserved. May not be cofrivial comparisons C 2009 Ling All R veghend, mineral, se deplased C=2,6,7,9 15. Show the steps in merging A and B into C where A = 8, 12, 19, 34 B = 3, 5, 15, 21 16. Use mergesort to sort the list 6, 3, 1, 9. Count the total number of comparisons, including part. WCN 02-200-000 fficiency of Algorithms 170 of 930 11. For each of the following lists, perform a bubble sort, and show the list after each exchange. Compare the number of exchanges done here and in the Practice Problem at the end of Section 3.3.3. a. 4, 8, 2,6 b. 12,3, 6, 8, 2, 5, 7 c. D, B, G, F, A, C, E, H 12. Explain why the bubble sort algorithm does (n) comparisons on an n-element list. 13. Suppose selection sort and bubble sort are both performed on a list that is already sorted. Does bubble sort do fewer exchanges than selection sort? Explain. 14. Bubble sort can be improved. Smart bubble sort keeps track of how many exchanges are done within any single pass through the unsorted section of the list. If no exchanges occur, then the list is sorted and the algorithm should stop. a. Write a pseudocode version of the smart bubble sort algorithm. b. Perform a smart bubble sort on the following list. How many comparisons are required? 7, 4, 12, 9, 11 c. Describe the best-case scenario for smart bubble sort on an n-element list. How many comparisons are required? How many exchanges are required? d. Under what circumstances does smart bubble sort do the same number of comparisons as regular bubble sort? 3. Split the list into two halves Sort the first half of the list using mergesort 4. 5. Sort the second half of the list using mergesort 6. Merge the two sorted halves A and B into a new sorted list C by comparing the next two items from A and B and always choosing the smaller value to go into C 7. Stop Mergesort works by using the result of mergesort on two smaller lists, so mergesort, like the Fibonacci sequence in Exercise 3, is a recursive algorithm. Step 6 in this algorithm deserves an example. Suppose that at one point in running mergesort we have two sorted lists A and B, as follows: A = 2,9 B = 6,7 To create C, we compare 2 from A and 6 from B. Because 2 is smaller, it is removed from A and goes into C. A = 9 B= 6,7 C=2 Now compare 9 from A and 6 from B. Because 6 is smaller, it is removed from B and goes into C. A=9 B=7 C = 2,6 Comparing 9 and 7 results in A = 9 B = C = 2,6,7 Finally, let us agree to count comparing 9 to nothing as a legitimate, if trivial, comparison resulting in 9, which is added to C, the final sorted list. A = B = Exercises 15-17 refer to still another sorting algorithm, called mergesort. Mergesort breaks the list to be sorted into smaller and smaller lists until there is just a bunch of one-element (and thus obviously sorted) lists, then assembles the smaller sorted lists back together into larger and larger sorted lists. Here is a pseudocode version: 1. Get values for n and the n list items 2. While the current list has more than 1 item, do Steps 3 through go Learning. All Rights Reserved. May not be cofrivial comparisons C 2009 Ling All R veghend, mineral, se deplased C=2,6,7,9 15. Show the steps in merging A and B into C where A = 8, 12, 19, 34 B = 3, 5, 15, 21 16. Use mergesort to sort the list 6, 3, 1, 9. Count the total number of comparisons, including part. WCN 02-200-000
Expert Answer:
Answer rating: 100% (QA)
Solutions Step 1 Explanation Bubble Sort is a comparisonbased sorting algorithm used to arrange elements We compare the adjacent elements and swaps th... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Lenders are willing to make low-down-payment FHA loans because the FHA guarantees the entire loan. guarantees the top 25% of the loan. insures the entire amount of the loan. insures the top 25% of...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
In Exercises 912, use the given conditions to write an equation for each line in point-slope form and general form Passing through (4, -7) and perpendicular to the line whose equation is x - 2y - 3 =...
-
An underwater scuba diver sees the Sun at an apparent angle of 45.0 above the horizon. What is the actual elevation angle of the Sun above the horizon?
-
Getty Company manufactures three products-A, B, and C-as a result of a joint process. During October, joint processing costs totaled $288,000. Details regarding each of the three products show:...
-
The distribution of the ages of the winners of the Tour de France from 1903 to 2016 is approximately bell-shaped. The mean age is 27.9 years, with a standard deviation of 3.3 years. Use the...
-
William H. Bailey, MD, executed a note payable to California Dreamstreet, a joint venture that solicited investments for a cattle breeding operation. Baileys promissory note read, Dr. William H....
-
Explain why accurate accounting information helps with the overall analysis of the business. Discuss how inaccurate or false information impacts the business. In your opinion, discuss the importance...
-
In this exercise you will be assuming the role of an Account Manager working within our Personal Care Appliances category during Amazon Black Friday. You act as a general manager responsible for...
-
Alex, Betty and Charles are each one-third partners for profits, losses and capital in the ABC Partnership, a cash basis calendar year partnership. On 1/1/X1 each of the partners contributed the...
-
The performance of the cache memory is measured in terms of ? What is cache memory and its performance?
-
Liquid reaction A --> 2B is taking place in a steady state packed bed reactor that has total available packing area (A) of 10 m. The density (p) and packing surface (a) of the catalyst per volume are...
-
Jack sends Joan an offer that says, "I'm offering to sell you my car for $2,000. If I don't hear from you in 10 days, I'll assume you're willing to buy the car for the listed price." Jack hears...
-
The pressure inside a plane is maintained at 1 Atm. What is the outward force exerted on a 1mx 2m cabin door if the outside pressure is 0.3 Atm? O O a. 160 N b. 1.40 N C. 1700 N d. 400 N
-
Economic Development Strategies, GIS, and Disasters Discussion Description Please post to Discussion - Module #6 - Economic Development Strategies and GIS by completing the following: Discussion Part...
-
How would your evaluate a continuous function f(my) Over region R in the xy-plane enclosed by triangle with vertices (0,1), (2,0) and (1,2)? Give reasons your answer. the for the
-
Before the latest financial crisis and recession, when was the largest recession of the past 50 years, and what was the cumulative loss in output over the course of the slowdown?
-
Frank, age 35, and Joyce, age 34, are married and file a joint income tax return for 2012. Their salaries for the year total $83,000 and they have taxable interest income of $4,000. They have no...
-
Jim is fired from his job as a waiter and decides to take an extended trip to Europe. After touring Europe for 3 months, Jim returns to look for a new job as a waiter. Are his job-hunting expenses...
-
Joan is a self-employed attorney in New York City. Joan took a trip to San Diego, CA, primarily for business, to consult with a client and take a short vacation. On the trip, Joan incurred the...
-
Power feed is not provided on the following drilling machine : (a) bench drill press (b) gang drilling machine (c) radial drilling machine (d) all of the above.
-
The lathe post not provided with power feed is (a) lead screw (b) carriage (c) compound rest (d) cross slide
-
External taper can be obtained by (a) taper attachment (b) form tool (c) compound rest (d) tail stock offset.
Study smarter with the SolutionInn App