Question

In: Computer Science

Prove the following: If a heap has one new leaf added that does not satisfy the...

Prove the following:

If a heap has one new leaf added that does not satisfy the condition that the leaf is greater than its parent, then sifting that leaf up until it is greater than its parent will produce a heap.

Solutions

Expert Solution

Array = {1, 3, 5, 4, 6, 13, 10, 9, 8, 15, 17}

Corresponding Complete Binary Tree is:
                 1
              /     \
            3         5
         /    \     /  \
        4      6   13  10
       / \    / \
      9   8  15 17

The task to build a Max-Heap from above array.

Total Nodes = 11.
Last Non-leaf node index = (11/2) - 1 = 4.
Therefore, last non-leaf node = 6.

To build the heap, heapify only the nodes:
[1, 3, 5, 4, 6] in reverse order.

Heapify 6: Swap 6 and 17.
                 1
              /     \
            3         5
         /    \      /  \
        4      17   13  10
       / \    /  \
      9   8  15   6

Heapify 4: Swap 4 and 9.
                 1
              /     \
            3         5
         /    \      /  \
        9      17   13  10
       / \    /  \
      4   8  15   6

Heapify 5: Swap 13 and 5.
                 1
              /     \
            3         13
         /    \      /  \
        9      17   5   10
       / \    /  \
      4   8  15   6

Heapify 3: First Swap 3 and 17, again swap 3 and 15.
                 1
              /     \
            17         13
          /    \      /  \
         9      15   5   10
        / \    /  \
       4   8  3   6

Heapify 1: First Swap 1 and 17, again swap 1 and 15, 
           finally swap 1 and 6.
                 17
              /      \
            15         13
          /    \      /  \
         9      6    5   10
        / \    /  \
       4   8  3    1
I

Related Solutions

Prove the following: When replacing the key in a node of a heap with a key...
Prove the following: When replacing the key in a node of a heap with a key that is greater than one, or greater than both, of its children, then sifting that node down (trading places with its smallest child) until it is less than all of its children will produce a heap.
Suppose H is a binary min-heap with n nodes, Prove the following facts: Any algorithm that...
Suppose H is a binary min-heap with n nodes, Prove the following facts: Any algorithm that must nd the maximum key of the heap must search all of the leaf nodes.
C++ Heap Tree:  Make a program called "priority_queue" that has the following operations using a heap and...
C++ Heap Tree:  Make a program called "priority_queue" that has the following operations using a heap and simulating a prioritized row of integers with higher priority value. I would appreciate if someone could help me with this code It has to include the following on the code: push Description: Add data to prioritized row Entry: An integer, which you want to add to the prioritized row Exit: Nothing Precondition: n is an integer Postcondition: The prioritized row contains new data. pop...
Demonstrating that a correlation exists does not prove that changes in one variable are the cause...
Demonstrating that a correlation exists does not prove that changes in one variable are the cause of changes in the other, partly because other factors which are undetected may be influencing both known variables. Thus, knowing that a correlation exists may lead to two or more different interpretations of the correlation. For each of the studies described below, decide whether the correlation is positive or negative and give two explanations for the finding. 1 A government study reveals that the...
What 3 manifest needs does McClelland identify? Give an example of how you can satisfy one...
What 3 manifest needs does McClelland identify? Give an example of how you can satisfy one of the three needs.
Match the plot with a possible description of the sample. A stem-and-leaf plot has the following...
Match the plot with a possible description of the sample. A stem-and-leaf plot has the following data, where the stems are listed first and the leaves are listed second: 18, 0 1 1 3 3 4 5 ; 19, 0 9 ; 20, 0 5 6 7 7 7 ; 21, 1 1 4 7 9 . Below the plot, a key reads: Key 18|0 = 180. 18 19 20 21 0 font size decreased by 6 1 font size...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts one integer parameter and returns that value raised to the third power. Write a method called randomNumber that returns a random floating-point number in the range of [-20.0, 50.0). (hints: use Random class in the method) Write a method called findMax that accepts three floating-point number as parameters and returns the largest one.(hints: use conditional statement in the method) Overload findMax that accepts one...
What are the new chemical equations when each one is individually added to the equation Fe3+...
What are the new chemical equations when each one is individually added to the equation Fe3+ + SCN-<--> FeSCN2+? There should be 8 new equations. One for each chemical that is added to the original equation sodium Oxalate, sodium nitrate, silver nitrate, potassium thiocyanate, sodium flouride, potassium nitrate, sodium phosphate, HCl
Prove that thickness of k17-{one edge} is 3 or 4? k17-{one edge} has 135 edges
Prove that thickness of k17-{one edge} is 3 or 4? k17-{one edge} has 135 edges
Prove that there is only one possible multiplication table for G if G has exactly 1,...
Prove that there is only one possible multiplication table for G if G has exactly 1, 2, or 3 elements. Analyze the possible multiplication tables for groups with exactly 4 elements, and show that there are two distinct tables, up to reordering the elements of G. Use these tables to prove that all groups with < 4 elements are commutative. (You are welcome to analyze groups with 5 elements using the same technique, but you will soon know enough about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT