Given an array A[1..7] = (17, 23, 12, 32, 24, 15, 9), run Heapsort (A, 7)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given an array A[1..7] = (17, 23, 12, 32, 24, 15, 9), run Heapsort (A, 7) to sort the array into non-decreasing order. HEAPSORT (A, n) 1 BUILD-MAX-HEAP(A, n) 2 for in downto 2 3 4 5 swap A[1] with A[i] A.heapsize = A.heapsize - 1 MAX-HEAPIFY(A, 1, i - 1) BUILD-MAX-HEAP(A, n) 1 for i= [n/2] downto 1 MAX-HEAPIFY(A, i, n) 2 MAX-HEAPIFY (A, i, n) LEFT (i) r = RIGHT (i) if 1 ≤ n and A[1] > A[i] largest = 1 - else largest = i if r ≤ n and A[r] > A[largest] largest = r if largest i 1 = exchange A[i] with A[largest] MAX-HEAPIFY (A, largest, n) You've already obtained the resultant array after the first line of Heapsort in the previous question. Now please show how the rest of the Heapsort algorithm is performed by listing the updated array or drawing the corresponding binary tree after each iteration of the for loop of Heapsort. Given an array A[1..7] = (17, 23, 12, 32, 24, 15, 9), run Heapsort (A, 7) to sort the array into non-decreasing order. HEAPSORT (A, n) 1 BUILD-MAX-HEAP(A, n) 2 for in downto 2 3 4 5 swap A[1] with A[i] A.heapsize = A.heapsize - 1 MAX-HEAPIFY(A, 1, i - 1) BUILD-MAX-HEAP(A, n) 1 for i= [n/2] downto 1 MAX-HEAPIFY(A, i, n) 2 MAX-HEAPIFY (A, i, n) LEFT (i) r = RIGHT (i) if 1 ≤ n and A[1] > A[i] largest = 1 - else largest = i if r ≤ n and A[r] > A[largest] largest = r if largest i 1 = exchange A[i] with A[largest] MAX-HEAPIFY (A, largest, n) You've already obtained the resultant array after the first line of Heapsort in the previous question. Now please show how the rest of the Heapsort algorithm is performed by listing the updated array or drawing the corresponding binary tree after each iteration of the for loop of Heapsort.
Expert Answer:
Related Book For
Microsoft Visual C# An Introduction to Object-Oriented Programming
ISBN: 978-1337102100
7th edition
Authors: Joyce Farrell
Posted Date:
Students also viewed these algorithms questions
-
Cigarette smoke contains any number of unhealthy substances, cyanide among them. One study modeled cyanide in the bloodstream after smoking a cigarette using C = 0.1 + 0.3t0.6e-0.17t, where C is the...
-
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...
-
A compare-exchange operation on two array elements A[i] and A[j], where i < j, has the form COMPARE-EXCHANGE (A, i, j) 1 If A[i] > A[j] 2 exchange A[i] with A[j] After the compare-exchange operation,...
-
Review the media landscape and system in The Bahamas. Which theories/typologies would fit the nation's media best? Explain your answer thoroughly using "Normative Theories of The Media Journalism and...
-
Describe several ways in which sellers can convince buyers that their products are of high quality. Which methods apply to the following products: Maytag washing machines, Burger King hamburgers,...
-
Explain the difference between an ordinary and special resolution and how these are made. Can company resolutions be made without the need for a meeting?
-
MyManagementLab Onlycomprehensive writing assignment for this chapter. LO.1
-
During 2012, Doxey Corporation had the following transactions and related events: Jan. 15 Issued 6,500 shares of common stock at par ($16 per share), bringing the total number of shares outstanding...
-
As of December 31 of the current year, Armani Companys records show the following. Cash $ 10,000 Accounts receivable 9,000 Supplies 7,000 Equipment 4,000 Accounts payable 11,000 Common stock 14,000...
-
The famous Y. S. Chang Restaurant is open 24 hours a day. Waiters and busboys report for duty at 3 A.M., 7 A.M., 11 A.M., 3 P.M., 7 P.M., or 11 P.M., and each works an 8-hour shift. The following...
-
1.Baltimore Manufacturing Company just completed its year ended December 31, 2018.Depreciation for the year amounted to $280,000: 15% relates to sales, 20% relates to administrative facilities, and...
-
Revisits scope, time, and cost baselines in the context of agile methodologies. Because agile includes several methodologies (like Scrum, Kanban, Extreme Programming, Feature-Driven Development) we...
-
Background information and task: Fed officials divided in July over need for more rate hikes, minutes show WASHINGTON, Aug 16 (Reuters) - Federal Reserve officials were divided over the need for more...
-
Questions: 1. What are the long-term prospects for the Chinese market? 2. Does it make sense for GM to produce automobiles for the Chinese market in China? Why? 3. What do you think would happen if...
-
The purpose of this assignment is to apply your knowledge of conflict management to a real-world situation so that you can enhance your skills in handling conflicts. It is crucial to carefully read...
-
Roy's Toys received a shipment of 100,000 rubber duckies from the factory. The factory couldn't promise that all rubber duckies are in perfect form, but they promised that the percentage of defective...
-
Remember that the primary goal of a firm is to maximize shareholder wealth by increasing the firm's intrinsic value. It is thus important to understand the impact of distributions-both in the form of...
-
Define deferred revenue. Why is it a liability?
-
The numbers array is a two-dimensional int array that contains three rows and five columns. The following statement should call the void calcTotal function, passing it the numbers array:...
-
A program contains a void function named getNewPrice. The function receives two double variables named oldPrice and newPrice. The function multiplies the contents of the oldPrice variable by 1.1 and...
-
Modify the solution shown earlier in Figure 7-2. The solution should now keep track of the number of times Sahirahs laser beam missed the spider. After saying You are safe now. The spider is dead.,...
-
20. An employment agency for the handicapped works closely with the City of Hanover. The employment agency is legally separate from the city but still depends on it for financial support. How should...
-
24. Government-wide financial statements make a distinction between program revenues and general revenues. How is that difference shown? a. Program revenues are offset against the expenses of a...
-
21. The Edison County Art Museum is legally separate from the City of Edison. Which of the follow ing is true? a. If the art museum qualifies as a special purpose local government, it cannot be a...
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App