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;
}