Question

In: Computer Science

Build a Max Heap using the following: A= {20, 15, 10, 14, 8, 6, 9}

Build a Max Heap using the following: A= {20, 15, 10, 14, 8, 6, 9}

Solutions

Expert Solution

Max heap is a specialized fully binary tree in which every parent node contains greater than or equal value than its child node.

Steps to build a Max Heap ( Max Heap Insertion) are:

Step 1: Create a new node at the end of heap

Step 2: Assign new value to the node

Step 3: Compare the value of this child node with its parent node

Step 4: If the value of parent is less than child, then swap them

Step 5: Repeat step 3 ans step 4 until heap propery holds.

  In the above example of building Max Heap, the elements are A={20,15,10,14,8,6,9}

Step 1: Take the first element 20, as the root node

Step 2: 15 and 10 are the child nodes of the root node 20. Now compare newnode (child) 15, with parent node 20. That means 15<20, so no swapping is required. Now compare newnode (child) 10, with parent node 20. That means 10<20, so no swapping is required.

Step 3: Child nodes of 15 are 14 and 8. Compare child node 14, with its parent node 15.Here, 14<15, so no swapping is needed. Now compare 8 with its parent node 15. Here, 8<15, so no swapping is needed.

Step 4: Child nodes of 10 are 6 and 9. Compare child node 6 with its parent node 10. Here 6<10, so no swapping is required. Now compare 9 with its parent node 10. Here 9<10, so no swapping is required.

Max Heap Insertion:

  


Related Solutions

Using the following data set: 10, 5, 2, 7, 20, 3, 13, 15, 8, 9 Apply...
Using the following data set: 10, 5, 2, 7, 20, 3, 13, 15, 8, 9 Apply the Merge sort algorithm. [Show to sorting process of the first half only] Apply the Quick sort algorithm [Show the first partitioning implementation]
Periods ​1% ​2% ​3% ​4% ​5% ​6% ​7% ​8% ​9% ​10% ​12% ​14% ​15% ​16% ​18%...
Periods ​1% ​2% ​3% ​4% ​5% ​6% ​7% ​8% ​9% ​10% ​12% ​14% ​15% ​16% ​18% ​20% 1 0.990 0.980 0.971 0.962 0.952 0.943 0.935 0.926 0.917 0.909 0.893 0.877 0.870 0.862 0.847 0.833 2 0.980 0.961 0.943 0.925 0.907 0.890 0.873 0.857 0.842 0.826 0.797 0.769 0.756 0.743 0.718 0.694 3 0.971 0.942 0.915 0.889 0.864 0.840 0.816 0.794 0.772 0.751 0.712 0.675 0.658 0.641 0.609 0.579 4 0.961 0.924 0.888 0.855 0.823 0.792 0.763 0.735 0.708 0.683 0.636...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of Aides Absent 5 8 11 15 4 2 7 1 4 6 14 19 3 5 8 In which of the following ranges you can find the Upper Control Limit of the control chart? 0.1427 0.1536 0.1677 Not computable with information available In which of the following ranges you can find the Lower Control Limit of the control chart? Does not exit...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Test score 67 67 87 89 87 77 73 74 68 72 58 98 98 70 77 Above we have the final averages of the last stats and I want to know if the class average falls within the boundaries of all my statistics classes for the past 20 years. Find the sample size, mean, and standard deviation of the data above (Table 1)....
The following is a sample of 20 measurements. 10 7 6 12 11 9 8 13...
The following is a sample of 20 measurements. 10 7 6 12 11 9 8 13 11 11 12 6 8 7 15 9 12 6 10 10 Compute the Sample mean (x), Sample variance (s2 ), and the Sample standard deviation (s). (round to two decimal places) Count the number of measurements in the intervals x ±s​, x ±2s​, x ±3s. Express each count as a percentage of the total number of measurements.
Consider the grouped frequency distribution. Class Limits 3-5 6-8 9-11 12-14 15-17 f 4 10 10...
Consider the grouped frequency distribution. Class Limits 3-5 6-8 9-11 12-14 15-17 f 4 10 10 5 10 (a) Find the mean. (Give your answer correct to two decimal places.) (b) Find the variance. (Give your answer correct to two decimal places.) (c) Find the standard deviation. (Give your answer correct to two decimal places.)
Given the following data: x 2 8 5 12 9 y 6 11 7 14 10...
Given the following data: x 2 8 5 12 9 y 6 11 7 14 10 a) draw/graph a scatter plot. b) by hand, find the correlation coefficient r. c) by hand, find b0 and b1. d) write the regression equation.
Table: x: 6, 2, 15, 9, 12, 5, 8 y: 8, 9, 4, 7, 6, 9,...
Table: x: 6, 2, 15, 9, 12, 5, 8 y: 8, 9, 4, 7, 6, 9, 8 1) Make the scatter diagram. 2) Find the equation of the regression line using the formulas given in class. They must appear the intermediate steps of substitutions. Round the answers to three decimal places. 3) Find the correlation coefficient using the formulas given in class. Steps should appear intermediates of substitutions. Round the answer to three decimal places. 4) Find the value predicted...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question 's scores, If three points were added to every score in this distribution, what would be the new mean? If three points were added to every score in this distribution, what would be the new standard deviation. Remember, you have already calculated population standard deviation in a previous problem. This problem requires two answers.
Week 1 2 3 4 5 6 Value 18 14 15 10 17 15 Using the...
Week 1 2 3 4 5 6 Value 18 14 15 10 17 15 Using the naïve method (most recent value) as the forecast for the next week, compute the following measures of forecast accuracy. (a) Mean absolute error If required, round your answer to one decimal place. (b) Mean squared error If required, round your answer to one decimal place. (c) Mean absolute percentage error If required, round your intermediate calculations and final answer to two decimal places. (d)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT