Question

In: Computer Science

Please answer full question thoroughly (A- D) showing detailed work. SUBMIT ORIGINAL work and ensure it...

Please answer full question thoroughly (A- D) showing detailed work. SUBMIT ORIGINAL work and ensure it is correct for thumbs up.

a) What is the effect of calling MAX-HEAPIFY(A, i) when the element A[I ]is larger than its children?

b) What is the effect of calling MAX-HEAPIFY(A, i) for i > A.heap-size/2?

c) The code for MAX-HEAPIFYis quite efficient in terms of constant factors, except possibly for the recursive call in line 10, which might cause some compilers to produce inefficient code. Write an efficient MAX-HEAPIFY that uses an iterative control construct (a loop) instead of recursion.

d)  Show that there are at most nodes of height h in any n-element heap.

Solutions

Expert Solution

a) When the element A[i] is larger than its children, just return to the calling function.

b) Under the given condition, i>A.heap-size/2, the node is a leaf node.

c) Below is the pseudo code:

MIN-HEAPIFY(A, i):
        while i ≤ heap-size[A]:
                l <- LEFT(i)
                r <- RIGHT(i)
                largest <- i
                if l ≤ heap-size[A] and A[l] > A[i]:
                        then largest <- l
                if r ≤ heap-size[A] and A[r] > A[largest]:
                        then largest <- r
                if largest ≠ i:
                        then swap(A[i], A[largest])
                                 i = largest
                else break

d) The question should be "Show that there are at most ⌈n/2h+1⌉ nodes of height h in any n-element heap.

Base: Height h=0. The number of leaves is ⌈n/2⌉=⌈n/20+1⌉.

Step: Let's assume it holds for nodes of height h−1. Let's take a tree and remove all it's leaves. We get a new tree with n−⌈n/2⌉=⌊n/2⌋ elements. Note that the nodes with height h in the old tree have height h−1 in the new one.

We will calculate the number of such nodes in the new tree. By the inductive assumption we have that T, the number of nodes with height h−1 in the new tree, is:

T=⌈⌊n/2⌋/2h−1+1⌉<⌈(n/2)/2h⌉=⌈n2h+1

As mentioned, this is also the number of nodes with height h in the old tree.


Related Solutions

Please answer below question with full detailed explanation in type written, no hand writing please. What...
Please answer below question with full detailed explanation in type written, no hand writing please. What is the basic difference between synchronous machine and induction machine? Why induction motor is more common as compared to induction generator?
Please answer the following by hand showing all arithmatic and original formulas, please do not use...
Please answer the following by hand showing all arithmatic and original formulas, please do not use a graphic calculator. The province of Ontario is planning to construct a new hydropower plant to help make energy prices more affordable, as well as to support improved public health and environmental quality. The construction of the hydropower plant will start by the beginning of 2023 and will take 3 years at a cost of $200 million per year. The cost of maintenance and...
Answer the following questions showing all work. Full credit will not be given to answers without...
Answer the following questions showing all work. Full credit will not be given to answers without work shown. If you use Minitab Express or StatKey include the appropriate output (copy + paste). If you do hand calculations show your work using the Word equation editor. Clearly identify your final answers. Output without explanation will not receive full credit and answers with no output or explanation will not receive full credit. Round all answers to 3 decimal places. If you have...
Answer the following questions showing all work. Full credit will not be given to answers without...
Answer the following questions showing all work. Full credit will not be given to answers without work shown. If you use Minitab Express or StatKey include the appropriate output (copy + paste). If you do any hand calculations show your work using the Word equation editor. Clearly identify your final answers. Output without explanation will not receive full credit and answers with no output or explanation will not receive full credit. Round all answers to 3 decimal places. If you...
PLEASE READ: This is one question with 3 parts to it, please answer the full question....
PLEASE READ: This is one question with 3 parts to it, please answer the full question. Mark M. Upp has just been fired as the university bookstore manager for setting prices too low (only 20 percent above suggest retail). He is considering opening a competing bookstore near the campus, and he has begun an analysis of the situation. There are two possible sites under consideration. One is relatively small, while the other is large. If he opens at Site 1...
Please - Please have an original assignment not copied because I have to submit to a...
Please - Please have an original assignment not copied because I have to submit to a citing program. The purpose of this assignment is to review the current state of development for your state's health information exchange (HIE) and current participation rate. Compare your state (New Jersey) to three states with similar demographics. Write a 1,000-1,250 word summary related to the ability of your state's HIE to share data and improve the following: Coordination of care Public health initiatives Evidence-based...
please be DETAILED with the answers! this is a ruminant nutrition question do not answer if...
please be DETAILED with the answers! this is a ruminant nutrition question do not answer if unsure A complete dairy diet contains 55% alfalfa, 40% corn and 5% cotton seed meal. List all of the chemical compounds in the diet (e.g. starch). For each compound you have listed, describe the fermentation process in the rumen. For each compound identify what % is fermented in the rumen and what % is digested in the intestine
Looking for a detailed work breakdown structure for a football stadium. Please do not answer it...
Looking for a detailed work breakdown structure for a football stadium. Please do not answer it with a definition. The more details the better.
(Please answer this question in an excel format if possible.) Please provide very detailed explanation and...
(Please answer this question in an excel format if possible.) Please provide very detailed explanation and answers if possible. The Poster Bed Company believes that its industry can best be classified as monopolistically competitive. An analysis of the demand for its canopy bed has resulted in the following estimated demand function for the bed: P ¼ 1760 12Q The cost analysis department has estimated the total cost function for the poster bed as TC ¼ 1 3 Q3 15Q2 þ...
Please answer only Question 12 and 13. Question 12: In reference to the original sequence (shown...
Please answer only Question 12 and 13. Question 12: In reference to the original sequence (shown in Question 8), classify each type of mutation present from Questions 9 to 11. Choose the best option for each. mutation #1    mutation #2    mutation #3 A. base substitution - silent mutation B. insertion - frameshift mutation C. deletion - frameshift mutation D. base substitution - missense mutation E. base substitution - nonsense mutation 3 points    QUESTION 13 Questions 9 to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT