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.
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...
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...
Consider the following struct that represents a node within a binary tree: struct Node { int...
Consider the following struct that represents a node within a binary tree: struct Node { int data; // Data of interest Node *left // Link to left subtree (nullptr if none) Node *right ; // Link to right subtree (nullptr if none) }; Complete the following function that computes the number of elements in a binary tree: // Counts the number of elements in the binary tree to which t points. // Returns the number of elements. int size(Node *t)...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); What is the result of the following query? select node_id, node_color, destination_id from node, edge; An inner join of the tables node and edge that lists origin node_id and node_color together with the node_id of the destination node for all those nodes that have outgoing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT