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...
-
Space Travel to the stars requires hundreds or thousands of years, even at the speed of light. Some people have suggested that we can get around this difficulty by accelerating the rocket (and its...
-
Your mother operates a small lumber business. She owns a tract of land with a stand of trees on it. She cuts down the trees, saws them into construction lumber, and sells the wood to builders. She...
-
Example 6.1 used sum(wtlossdat ["B"] *wtlossdat["y"])/4 to compute the main effect of $\mathrm{C}$.a. Explain why the espression is divided by 4 ? b. Write an $\mathrm{R}$ function to calculate the...
-
CLV calculation example Using the Tier One customer data in the scenario, the CLV for a Tier One customer is calculated as follows: Where Tier One has GP = $4,500 | RR = 0.85 | DR = 0.10| AC = $2,500...
-
At the beginning of Year 1, Copeland Drugstore purchased a new computer system for $170,000. It is expected to have a five-year life and a $30,000 salvage value. Required a. Compute the depreciation...
-
You counted the petty cash fund balance of Rainbow Corporation at 9:00 o' clock in the morning of January 4, 2022, and you obtained the following details: Bills and coins Paid vouchers (all dated...
-
New Homes has a bond issue with a coupon rate of 5.5 percent that matures in 8.5 years. The bonds have a par value of $1,000 and a market price of $1,045. Interest is paid semiannually. What is the...
-
When developing the Business Plan, who are the stakeholders involved and what is their role in the development of the Business Plan. STAKEHOLDERS Criteria Identify two (2) internal and external...
-
Seven years ago, Henri bought a house valued at $249 500.00. Determine the current value of his house if it appreciated at an average rate of 8.00% per year. (2 marks)
-
2. Consider the graph G with vertices V = {1,2,3,4,5} and edges E {{1,2}. {2,3}, {3.1}, {3, 4}, {4, 5}, {5,1}}. (a) Draw G. (b) How many cycles does G have? List them. (c) Is G bipartite? Explain....
-
Let F(x) = =1 tan (x-1) x < 1 sin (x 1) 1 x Find lim F(x). x+1+ lim F(x) = x+1+
-
We would like to cover a rectangular area by two kinds of tiles: 1 x 1 and 1 x 2 tiles (the 1 x 2 tiles can be rotated). Give a recurrence and boundary conditions for the number of ways to cover the...
-
Consider the following reaction:2CH3OH(g)+3O2(g)?2CO2(g)+4H2O(g) Each of the following moleculardiagrams represents an initial mixture of the reactants. (Figure 1)How many CO2 molecules would be...
-
Anna, a high school counselor, devised a program that integrates classroom learning with vocational training to help adolescents at risk for school dropouts stay in school and transition to work...
-
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.,...
-
Using a search engine such as Google, search for power of a hypothesis test. Describe what the power of a hypothesis test is.
-
H 0 : The lottery is fair. Ha: The lottery is biased. Without using the terms null hypothesis and alternative hypothesis, identify the type I error and identify the type II error.
-
What do p, p, and P-value represent?
Study smarter with the SolutionInn App