Algorithm to insert element to a max-heap sequentially, Data Structure & Algorithms

Q. Write  down the  algorithm  to  insert  an  element  to  a  max-heap  which  is  represented sequentially.          

Ans:

The algorithm to insert an element "newkey" to a max heap of size i-1 where i>=1:

s=i;

parent=s div 2;

key[s]=newkey;

while(s<>0 && key[parent]<=key[s])

{

/*interchange parent and child*/

temp=key[parent]; key[parent]=key[s]; key[s]=temp;

s=parent;

parent=s div 2;

}

Posted Date: 7/10/2012 6:24:51 AM | Location : United States







Related Discussions:- Algorithm to insert element to a max-heap sequentially, Assignment Help, Ask Question on Algorithm to insert element to a max-heap sequentially, Get Answer, Expert's Help, Algorithm to insert element to a max-heap sequentially Discussions

Write discussion on Algorithm to insert element to a max-heap sequentially
Your posts are moderated
Related Questions
Explain in brief about the Container An entity which holds finitely many other entities. Just as containers such as boxes, baskets, bags, pails, cans, drawers, and so for

i need the full concept of it... please can anyone provide

There are three kinds of tree traversals, namely, Postorder , Preorder and Inorder. Preorder traversal: Each of nodes is visited before its children are visited; first the roo

Q. What do you understand by the term sparse matrix? How sparse matrix is stored in the memory of a computer? Write down the function to find out the transpose of a sparse matrix u

Board coloring , C/C++ Programming

Linear search employee an exhaustive method of verified each element in the array against a key value. Whereas a match is found, the search halts. Will sorting the array before uti

what is frequency count with examble

Construct G for α, n, and W given as command line parameters. Throw away edges that have an asymmetric relation between nodes. That is, if A is connected to B, but B is not connect

Given is the structure of an AVL tree: struct avl { struct node *left; int info; int bf; struct node *right; }; 2) A multiway tree of n order is an ord

Q. How can we free the memory by using Boundary tag method in the context of Dynamic memory management?