To add a new element X to a heap:

A) If the tree is empty, make X the root of a new tree; otherwise, compare X to the root, if X is less, put it in the left subtree, if it is greater, put it in the right subtree
B) First add X in the position of the root. If X is a leaf, or is less than its children, stop. Otherwise, repeatedly swap X with the smaller of its two children until X becomes a leaf or becomes less than its children.
C) Add X as a leaf, taking care to preserve the completeness of the heap. If X is now the root, or is greater than its parent, stop. Otherwise, repeatedly swap X with its parent until X becomes the root or becomes greater than its parent.
D) Insert X using the same algorithm for insertion in a binary search tree. If the tree remains balanced, stop. Otherwise, execute a rebalancing operation.


C) Add X as a leaf, taking care to preserve the completeness of the heap. If X is now the root, or is greater than its parent, stop. Otherwise, repeatedly swap X with its parent until X becomes the root or becomes greater than its parent.

Computer Science & Information Technology

You might also like to view...

What is significant about big-theta notation (?)?

a. Asymptotically tighter bound than O(n) b. Compute Big-O of f(n) c. Determine the Big-O error factor d. Find the optimal case of an algorithm

Computer Science & Information Technology

A piece of paper with a pencil is the image used for the ________ icon

Fill in the blank(s) with correct word

Computer Science & Information Technology

Can I initiate a "forced failover" for my MySQL Multi-AZ DB Instance deployment?

A. Only in certain regions B. Only in VPC C. Yes D. No

Computer Science & Information Technology

When does the push operation throw a StackException?

What will be an ideal response?

Computer Science & Information Technology