Computer Science, asked by devendra123world, 3 months ago

write an algorithm to insert element in a heap?​

Answers

Answered by patelpurushottam970
0

Answer:

Insert -2 into a following heap:

  1. Insert a new element to the end of the array:
  2. In the general case, after insertion, heap property near the new node is broken:
  3. To restore heap property, algorithm sifts up the new element, by swapping it with its parent:
  4. Now heap property is broken at the root node:
  5. Keep sitting:

please mark me as a brainlist

Answered by Anonymous
1

Inserting an element into a heap

In this article we examine the idea laying in the foundation of the heap data structure. We call it sifting, but you also may meet another terms, like "trickle", "heapify", "bubble" or "percolate".

Insertion algorithm

Now, let us phrase general algorithm to insert a new element into a heap.

  1. Add a new element to the end of an array;
  2. Sift up the new element, while heap property is broken. Sifting is done as following: compare node's value with parent's value. If they are in wrong order, swap them.

hope it helps you...

mark as brainliest plzz ❤️

Similar questions