delection/max extraction in max heap to write the pseudo code for a function that extracts the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
delection/max extraction in max heap to write the pseudo code for a function that extracts the element with maximum value from a max heap, removes that element from the array, restores the array to a max heap, and returns the extracted maximum value in a variable max. Using the pseudo code as guidance, write python code to implement this deletion/max extraction algorithm in the code cell below. You can test your code using the input max-heap array A = [9, 7, 6, 5, 4, 1, 2]. Hint: if your code is correct, the returned max value should be 9, and the restored max heap (after deleting the element with max value) should be [7, 5, 6, 2, 4, 1] [ ] # please write your code for Task 5 in this code cell. Extra Credit Task 6. (bonus 1 point) Implement an algorithm that sorts all elements in an array using max heap or min heap data structure. Hint. you can use existing functions above, e.g. build_max_heap, heap_extract_max, or similar functions using min heap to implement the sorting algorithm. Test the correctness of your code using the input array A = [2,7,1,5,4,9,6]. If your code is correct, the function should return an array that has its elements sorted, either from smallest to largest or from largest to smallest. Print the returned sorted array to verify correctness. [ ] # please write your code for Task 6 in this code cell. delection/max extraction in max heap to write the pseudo code for a function that extracts the element with maximum value from a max heap, removes that element from the array, restores the array to a max heap, and returns the extracted maximum value in a variable max. Using the pseudo code as guidance, write python code to implement this deletion/max extraction algorithm in the code cell below. You can test your code using the input max-heap array A = [9, 7, 6, 5, 4, 1, 2]. Hint: if your code is correct, the returned max value should be 9, and the restored max heap (after deleting the element with max value) should be [7, 5, 6, 2, 4, 1] [ ] # please write your code for Task 5 in this code cell. Extra Credit Task 6. (bonus 1 point) Implement an algorithm that sorts all elements in an array using max heap or min heap data structure. Hint. you can use existing functions above, e.g. build_max_heap, heap_extract_max, or similar functions using min heap to implement the sorting algorithm. Test the correctness of your code using the input array A = [2,7,1,5,4,9,6]. If your code is correct, the function should return an array that has its elements sorted, either from smallest to largest or from largest to smallest. Print the returned sorted array to verify correctness. [ ] # please write your code for Task 6 in this code cell.
Expert Answer:
Answer rating: 100% (QA)
Heres a Python implementation of the function that extracts the element with the maximum value from ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
A factory produces a certain product, and the production process involves four consecutive stages. The probability that the product will be defective at the first stage is 0.2, at the second stage is...
-
9.1 Exercise (JDK Source Code): Extract the source code of the class Math from the JDK source code ("$JAVA_HOME" "src.zip" "Math.java" under folder "java.lang"). Study how constants such as E and...
-
According to a study conducted by the Gallup organization, the proportion of Americans who are afraid to y is 0.10. A random sample of 1100 Americans results in 121 indicating that they are afraid to...
-
Costs of Acquisition the invoice price of a machine is $50,000. Various other costs relating to the acquisition and installation of the machine including transportation, electrical wiring, and...
-
Figure 19 shows a contour map for the depth of a river between a dam and a bridge. Approximate the volume of water between the dam and the bridge. Hint: Slice the river into eleven 100-feet sections...
-
Veronicas expense report was reviewed by her company, and she was accused of taking her best friend on a business conference to Paris and charging all expenses for both of them on a company credit...
-
Carbon monoxide is burned with excess air at 1 atm in an adiabatic reactor. The reactants are fed at 25C and the final temperature (i.e., the adiabatic flame temperature) is 1400C. (a) Calculate the...
-
14.An equi-concave lens of radius of curvature 15 cm and = 1.5 is placed in water (=1.33). If one surface is silvered, then image distance from lens when an object is placed at distance of 14 cm from...
-
Stainless Steel Specialties (SSS) is a manufacturer of hot water-based heating systems for homes and commercial businesses. The company has grown about 10% in each of the past five years. The company...
-
The Ruins Ltd. has a preliminary profit (before recording a provision) of 900.000 in the accounting period 2013 and the next 3 years. In the year 2013 it signed a contract for the construction of a...
-
Twenty-four milligrams of a drug is administered into the body. At the end of each hour, the amount of drug present is half what it was at the end of the previous hour. What amount of the drug is...
-
Prepare a budget for a family of four with an annual income of \(\$ 100,000\).
-
Find the limit (if it exists) as \(n ightarrow \infty\) for each of the sequences in Problems 43-56. \(\lim _{n ightarrow \infty} \frac{4 n^{4}+10 n-1}{9 n^{3}-2 n^{2}-7 n+3}\)
-
Find the derivative, \(f^{\prime}(x)\), of each of the functions in Problems 37-42 by using the derivative definition or the derivative of the exponential function. \(f(x)=3+2 x-3 x^{2}\)
-
Find the limit (if it exists) as \(n ightarrow \infty\) for each of the sequences in Problems 43-56. \(\lim _{n ightarrow \infty} \frac{3 n^{2}-7 n+2}{5 n^{4}+9 n^{2}}\)
-
The following code imports this file into MATLAB and plots the power spectrum of the signal. clear all clear all variables ('Flute.nonvib.ff.C4.stereo.aif'); [x, Fs] =audioread a=length (x); al-pow2...
-
Why did management adopt the new plan even though it provides a smaller expected number of exposures than the original plan recommended by the original linear programming model?
-
Listing 16.4, ComboBoxDemo.java, gives a program that lets the user view a country?s flag image and description by selecting the country from a combo box. The description is a string coded in the...
-
Write a program that animates the linear search algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random order. The array elements are displayed in a histogram, as...
-
Rewrite the fib method in Listing 18.2 using iterations. To compute fib(n) without recursion, you need to obtain fib(n - 2) and fib(n - 1) first. Let f0 and f1 denote the two previous Fibonacci...
-
When randomly selecting a day of the week, it is certain that you will select a day containing the letter y, so P(y) = 1. For Exercises 510, decide whether the statement makes sense (or is clearly...
-
If there is a 0.9 probability that it will rain sometime today, then there is a probability of 0.1 that it will not rain sometime today. For Exercises 510, decide whether the statement makes sense...
-
Rolling a die and getting an outcome that is greater than 2. For Exercises 1118, use the theoretical method to determine the probability of the given outcome or event. State any assumptions that you...
Study smarter with the SolutionInn App