Question

In: Computer Science

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.

Solutions

Expert Solution

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.

The proof is shown below considering a general heap:


Related Solutions

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.
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.
Write a complete C++ program to implements a Min-heap. Each node will contain a single integer...
Write a complete C++ program to implements a Min-heap. Each node will contain a single integer data element. Initialize the Min-heap to contain 5 nodes, with the values 8, 12, 24, 32, 42. The program should allow for the insertion and deletion of nodes while maintaining a Min-Heap. The program should allow the user to output data in Preorder, Inorder and Postorder. The program should loop with menu items for each of the above objectives and the choice to quit.
This problem requires you to use a heap to store items, but instead of using a key of an item to determine where to store the item in the heap
This problem requires you to use a heap to store items, but instead of using a key of an item to determine where to store the item in the heap, you need to assign a priority (key) to each item that will determine where it is inserted in the heap 7a) Show how to assign priorities to items to implement a first-in, first-out queue with a heap. 7b) Show how to assign priorities to items to implement a first-in, last-out stack with...
Prove that the entropy of a node never increases after splitting it into smaller children nodes.
Prove that the entropy of a node never increases after splitting it into smaller children nodes.
a tree is binary, if every node has at most two children nodes. prove that the...
a tree is binary, if every node has at most two children nodes. prove that the maximum of nodes in a binary tree of height h is 2^(h+1)-1
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...
Implement a priority queue using a DoublyLinkedList where the node with the highest priority (key) is...
Implement a priority queue using a DoublyLinkedList where the node with the highest priority (key) is the right-most node. The remove (de-queue) operation returns the node with the highest priority (key). If displayForward() displays List (first-->last) : 10 30 40 55 remove() would return the node with key 55. Demonstrate by inserting keys at random, displayForward(), call remove then displayForward() again. You will then attach a modified DoublyLinkedList.java (to contain the new priorityInsert(long key) and priorityRemove() methods). Use the provided...
in java This class will require the following fields: Node<T> head: the first Node in the...
in java This class will require the following fields: Node<T> head: the first Node in the chain Node<T> tail: the last Node in the chain int size: Keeps a count of the number of Nodes in the chain Your LinkedList class must also support the following public methods. LinkedList(): A default constructor sets both pointers to null and sets the size to 0. int size(): Returns the size of the LinkedList. void push_back(T): Creates a new Node and assigns it...
Create a binary search tree of stacks where each node contains a key and a stack.
IN C++   Create a binary search tree of stacks where each node contains a key and a stack. In this binary search tree, when adding a new element to the tree it is inserted based off of its key value; if that key value already exist then the element is pushed into the stack at that location, if the key value does not exist a node element is added to the tree to reflect that key, and a empty...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT